C# 当以键盘为焦点时,WPF组合框的高列表边框
这是我第一次在stackoverflow上发帖 我制作了自己的combobox,它继承了combobox。我只在可编辑模式下使用它 当组合框有键盘焦点时,我想把边框涂成蓝色,就像我们在文本框上看到的那样 我有一个XAML解决方案,它工作得非常完美,但我想在代码隐藏中完成它,因为我将combobox放在一个DLL中,并且我在RessoucheFiles和DLL方面有问题 下面的XAML可以工作。但我希望它在代码背后C# 当以键盘为焦点时,WPF组合框的高列表边框,c#,wpf,combobox,C#,Wpf,Combobox,这是我第一次在stackoverflow上发帖 我制作了自己的combobox,它继承了combobox。我只在可编辑模式下使用它 当组合框有键盘焦点时,我想把边框涂成蓝色,就像我们在文本框上看到的那样 我有一个XAML解决方案,它工作得非常完美,但我想在代码隐藏中完成它,因为我将combobox放在一个DLL中,并且我在RessoucheFiles和DLL方面有问题 下面的XAML可以工作。但我希望它在代码背后 <Style x:Key="ComboBoxToggleButton" Ta
<Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="Focusable" Value="false"/>
<Setter Property="ClickMode" Value="Press"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border x:Name="templateRoot" SnapsToDevicePixels="true" Background="{StaticResource ComboBox.Static.Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{StaticResource ComboBox.Static.Border}">
<Border x:Name="splitBorder" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" SnapsToDevicePixels="true" Margin="0" HorizontalAlignment="Right" BorderThickness="1" BorderBrush="Transparent">
<Path x:Name="arrow" VerticalAlignment="Center" Margin="0" HorizontalAlignment="Center" Fill="{StaticResource ComboBox.Static.Glyph}" Data="F1 M 0,0 L 2.667,2.66665 L 5.3334,0 L 5.3334,-1.78168 L 2.6667,0.88501 L0,-1.78168 L0,0 Z"/>
</Border>
</Border>
<ControlTemplate.Triggers>
<!--This paint the border blue -->
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
</MultiDataTrigger.Conditions>
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Border}"/>
</MultiDataTrigger>
<!--This paint the border blue -->
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
这是行不通的。它正在绘制内部文本框的边框
我也尝试过:
var template = this.Template;
var myControl = template.FindName("templateRoot", this);
Debug.Print(myControl.GetType().ToString());
它打印:“System.Windows.Controls.Grid”,告知templateRoot是一个网格。因此没有边界
但是如果我读对了XAML,它会说templateRoot是一个边界
我做错了什么?我发现的templateRoot是错误的?这对我很有用:
editableTextBox.BorderThickness = new Thickness(10);
editableTextBox.BorderBrush = Brushes.Green;
嗨,Martin,这只绘制内部边框,而不是下拉按钮周围的边框。我正在编辑模式下使用组合框。
editableTextBox.BorderThickness = new Thickness(10);
editableTextBox.BorderBrush = Brushes.Green;