【发布时间】:2011-04-09 04:06:28
【问题描述】:
我正在尝试将样式应用于组合框,但组合框本身消失了,而不是被应用。请检查以下 xaml 代码进行用户控制。
【问题讨论】:
标签: wpf wpf-controls
我正在尝试将样式应用于组合框,但组合框本身消失了,而不是被应用。请检查以下 xaml 代码进行用户控制。
【问题讨论】:
标签: wpf wpf-controls
你没有在你的风格的控制模板中指定任何视觉元素,只是一个触发器。 它将呈现空模板 iirc。
最好以您的风格编辑 ComboBox 的 Trigger 集合以添加该触发器,并且您将保留默认 ControlTemplate。
【讨论】:
问题是您正在重新定义 ControlTemplate 中没有任何可视化树:
<Style x:Key="comboBoxStyle" TargetType="{x:Type local:PASCustomComboBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:PASCustomComboBox}">
<ControlTemplate.Triggers>
<Trigger Property="local:PASCustomComboBox.IsEnabled" Value="false">
<Setter Property="Background" Value="Red"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
您需要样式上的触发器而不是控件模板:
<Style x:Key="comboBoxStyle" TargetType="{x:Type local:PASCustomComboBox}">
<Style.Triggers>
<Trigger Property="local:PASCustomComboBox.IsEnabled" Value="false">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
【讨论】: