I need to create a dropdown menu, or combobox, for a Windows Forms application which contains a small image and then a string of text next to it. Basically, you can think of each 'row' in the dropdown as needing to have an icon and then the name of the icon to the right of the icon. I am having trouble doing this -- in fact, I've been completely unsuccessful. Does anyone know of a way to accomplish this task? Any help will be greatly appreciated. Thanks!
相关问题
- Views base64 encoded blob in HTML with PHP
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- How to get the background from multiple images by
- Why am I getting UnauthorizedAccessException on th
I resolved the problem, i did this:
ComboBox MarcadorNS = new ComboBox(); MarcadorNS.Height = 30; MarcadorNS.Width = 150; MarcadorNS.SelectedValuePath = "Uid"; foreach (var temporalItem in GetPredefinedKinds()) { Image ImagenCombo = new Image(); ImagenCombo.Source = new BitmapImage(new Uri( "Imagenes/Marcadores/" + temporalItem.Name.ToLower() + ".png", UriKind.Absolute)); ImagenCombo.Height = 28; ImagenCombo.Width = 28; ImagenCombo.VerticalAlignment = VerticalAlignment.Top; ImagenCombo.HorizontalAlignment = HorizontalAlignment.Left; Label textoCombo = new Label(); textoCombo.VerticalAlignment = VerticalAlignment.Top; textoCombo.HorizontalAlignment = HorizontalAlignment.Left; textoCombo.Content = BaseDatos.NombresDeMarcadores(temporalItem.ToString()); Grid GridCombo = new Grid(); GridCombo.Uid = ObtenerMarcador(temporalItem.ToString()); StackPanel stackCombo = new StackPanel(); stackCombo.Orientation = Orientation.Horizontal; stackCombo.Children.Add(ImagenCombo); stackCombo.Children.Add(textoCombo); GridCombo.Children.Add(stackCombo); MarcadorNS.Items.Add(GridCombo);
Result
Not sure about images but this should work for the strings:
Very helpful.. some optimisations :
and ...
I was able to come up with some very simple code to perform this (see snippet below). The code creates a control that is a dropdown control which shows a small colored square and that color's name in the same row (see photo). Thanks for the links provided for this back when it was originally posted! Hopefully this control can help someone else out in the future.
Image:
Code:
Does this suit your needs
NOTE: This code is from user que dal's optimization If you wish to have a string that isn't just the name of the color, change DropDownItem to have 2 arguments, the string and the color, then just change how the brush sets the color, as such:
You must then change the dropdown item as such:
Hope this was helpful :)