在 WPF 中更改 Combobox 的边框颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32479606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:24:02  来源:igfitidea点击:

Change border color of Combobox in WPF

c#wpf

提问by Deepak

How do I change the border color of a WPF combo box, I've tried everything but it remains the same.

如何更改 WPF 组合框的边框颜色,我已经尝试了所有方法,但它保持不变。

ComboBox with default border

带默认边框的组合框

My Mark up:

我的标记:

<ComboBox Canvas.Left="12" Canvas.Top="44" Height="32"Name="cmbDeviceList" Width="158" Foreground="#000000" BorderBrush="#2071B9" BorderThickness="2" FontFamily="Microsoft Sans Serif" FontSize="15" IsEditable="True" IsReadOnly="True" />

回答by Martin Liversage

Set the property BorderBrushto the desired color or brush:

将属性BorderBrush设置为所需的颜色或画笔:

<ComboBox Margin="10" BorderBrush="Red">
  <ComboBoxItem>No Device Selected</ComboBoxItem>
</ComboBox>

Screenshot:

截屏:

Screenshot of combo box with red border

带有红色边框的组合框的屏幕截图

回答by Ramankingdom

The below XAML snippet is for combobox. The BorderBrush will define the color and Border Thickness will define the thickness of line

下面的 XAML 片段用于组合框。BorderBrush 将定义颜色,Border Thickness 将定义线条的粗细

<ComboBox Width="200" Height="30" BorderBrush="Blue" BorderThickness="3"></ComboBox>