更改WPF组合框的边框颜色 [英] Changing the border colors of a WPF combobox
问题描述
所以我试图改变表达式混合中我的组合框的样式。
So I am trying to change the style of my combobox in Expression blend.
我做的是创建一个组合框,并且右键单击>编辑模板>编辑副本
What I did was create a combobox, and went RightClick > Edit Template > Edit a Copy
我可以更改组合框的颜色,但背景 ,以及组合框的边框。这是一个屏幕,您可以看到:
And I can change the colors of the combobox, except there is a white border in between the background of the combobox, and the border of the combobox. Here is a screen so you can see:
正如你所看到的,蓝色和红色之间有一个边界。据我所知,改变combobox颜色的代码如下:
As you can see, there is a while border between the blue and red. As far as I can tell, the code to change the color of combobox is the following:
<ToggleButton Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay,
RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource
ComboBoxReadonlyToggleButton}" BorderBrush="Red" Background="Blue"/>
但无论如何,总有一个白色边框。如何摆脱它?
But no matter what, there is always a white border. How do i get rid of it?
推荐答案
我知道这是一个老问题,这个问题,这是我发现的第一件事情之一。
I know this is an old question, and it's specific to blend but when googling for this problem, this is one of the first things I found.
一个非常简单的例子来解决这个问题,比第一个提到的第一个问题复杂一点,就是设置Style属性。 (不确定这适用于混合,因为我不使用混合,但对于简单的wpf在visual studio,这样的工作)
A really simple example of a way to fix this, that is a little less complex than the first answer mentioned is to set "Style" Properties. (Not sure this applies to blend since I don't use blend, but for simple wpf in visual studio, this works)
例如,下面的代码创建一个窗口
For example, this code below creates a window just like the one mentioned in the question, but with the white lines (in the drop down items) editable.
<ComboBox Background="Blue" BorderBrush="Red">
<ComboBox.ItemContainerStyle>
<!-- Without this style section, there are white lines around the borders. Even if you set these properties in the comboBoxItem areas -->
<Style TargetType="ComboBoxItem">
<Setter Property="Background" Value="Green"/>
<Setter Property="BorderBrush" Value="Purple"></Setter>
</Style>
</ComboBox.ItemContainerStyle>
<ComboBoxItem MouseMove="schedule" Name="cbi1">schedule</ComboBoxItem>
</ComboBox>
这篇关于更改WPF组合框的边框颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!