BackgroundColor中的项目组合框WPF

编程入门 行业动态 更新时间:2024-10-28 16:22:08
本文介绍了BackgroundColor中的项目组合框WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我做一个WPF并具有计算机上的avaible端口的列表的组合框。我想改变这些项目的颜色

I am doing a WPF and have a comboBox which has a list of the avaible ports on the computer. I want to change the color of these items.

我的组合框是这些:

<ComboBox HorizontalAlignment="Left" Margin="445,0,0,0" VerticalAlignment="Top" Width="120" Loaded="ComboBoxLoaded" SelectionChanged="ComboBoxSelectionChanged" Grid.Column="1" Background="#849096" Foreground="White"/>

而这些是加载它的方法:

And these is the method to loaded it:

private void ComboBoxLoaded(object sender, RoutedEventArgs e) { string [] portsList = PrintPorts(); // get the ComboBox reference var comboBox = sender as ComboBox; // assign the ItemsSource to the List comboBox.ItemsSource = portsList; // make the first item selected comboBox.SelectedIndex = 0; }

我尝试了很多东西,但没有任何工程。有人知道该怎么办呢?谢谢!

I was trying a lot of things but nothing works. Someone knows how to do it? Thanks!!

推荐答案

要更改单个项目的背景颜色,您可以修改 ItemContainerStyle ,是这样的:

To change the background color of the individual items you can change the ItemContainerStyle, something like:

<ComboBox> ... <ComboBox.ItemContainerStyle> <Style TargetType="{x:Type ComboBoxItem}"> <Setter Property="Background" Value="Blue" /> </Style> </ComboBox.ItemContainerStyle> ... </ComboBox>

这将设置背景颜色 ComboBoxItem s到蓝色

This will set the background color on the ComboBoxItems to Blue

更多推荐

BackgroundColor中的项目组合框WPF

本文发布于:2023-11-05 15:30:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561218.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组合   项目   BackgroundColor   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!