【发布时间】:2018-04-20 16:10:04
【问题描述】:
我正在尝试对 wpf 中的组合框进行一些操作,首先我的组合框看起来像:
<ComboBox SelectedValuePath="Key" DisplayMemberPath="Value.ModuleName" controls:TextBoxHelper.Watermark="All" Height="2" IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding Modules}" commands:PropertyChangeBehavior.Command="{Binding ModuleCommand}"
SelectedValue="{Binding SelectedModule, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Value.IsWarning }" Value="True">
<Setter Property="Background" Value="#FF6666" />
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
它的作用是,当组合框中的字典类属性警告设置为 true 时,我得到彩色背景,并且工作正常。 But it does not work when that element selected, is there any way to do when, selected element has is warning property set it would change it selected background as well and if its false it behaves normal, so far I tried adding one more trigger:
<DataTrigger Binding="{Binding Path=SelectedItem.Content}" Value="True">
<Setter Property="Background" Value="#FF6666" />
</DataTrigger>
还有:
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" Value="#FF6666"/>
</Trigger>
但运气不好,这有可能吗。
【问题讨论】: