Placing Images and Strings with a C# Combobox

前端 未结 5 1629
傲寒
傲寒 2020-12-01 14:30

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 o

5条回答
  •  醉酒成梦
    2020-12-01 15:36

    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

提交回复
热议问题