Wpf 根据IsEditable属性设置组合框的默认填充
我已将所有文本框和组合框设置为默认填充为“1,3”。当ComboxBox可编辑时,填充看起来与文本框相同。但是当Wpf 根据IsEditable属性设置组合框的默认填充,wpf,xaml,Wpf,Xaml,我已将所有文本框和组合框设置为默认填充为“1,3”。当ComboxBox可编辑时,填充看起来与文本框相同。但是当IsEditable默认为false时,填充看起来不一样 在App.xaml中,我已经有: <Application.Resources> <Style TargetType="TextBox"> <Setter Property="Padding" Value="1,3"/> </Style> &
IsEditable
默认为false时,填充看起来不一样
在App.xaml中,我已经有:
<Application.Resources>
<Style TargetType="TextBox">
<Setter Property="Padding" Value="1,3"/>
</Style>
<Style TargetType="ComboBox">
<Setter Property="Padding" Value="1,3"/>
</Style>
</Application.Resources>
在App.xaml中,如何将所有具有
IsEditable=“False”
属性的组合框设置为具有Padding=“6,3,5,3”
?这是在所有适用组合框上使用键控样式的绝佳机会:
<Style TargetType="ComboBox" x:Key="EditableComboBoxStyle">
<Setter Property="IsEditable" Value="False"/>
<Setter Property="Padding" Value="6,3,5,3"/>
</Style>
这将覆盖应用它的任何组合框的默认样式。您可以使用触发器根据组合框的属性(在您的情况下是可编辑的)更改填充。要执行此操作,请按以下方式设置组合框的样式:
<Style TargetType="{x:Type ComboBox}">
<Setter Property="Padding" Value="1,3"/>
<Style.Triggers>
<Trigger Property="IsEditable" Value="False">
<Setter Property="Padding" Value="6,3,5,3"/>
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="Padding" Value="1,3"/>
<Style.Triggers>
<Trigger Property="IsEditable" Value="False">
<Setter Property="Padding" Value="6,3,5,3"/>
</Trigger>
</Style.Triggers>
</Style>