如何通过MVVM更改组合框选定项目颜色?

时间:2013-08-19 07:28:50

标签: wpf mvvm

任何人都可以给我一些关于如何通过MVVM更改组合框所选项目颜色的示例。 我使用WPF作为UI。

2 个答案:

答案 0 :(得分:0)

在您的ViewModel获取选定项目(如果您正在使用ICollectionView,然后使用用户CurrentItem),并在View中使用DataTrigger更改所选项目的样式。

答案 1 :(得分:-1)

这可以帮到你: https://stackoverflow.com/a/9906687/1468507

无论您是在谈论选择还是重点。

编辑(将所选文字设置为红色): 这应该可以解决问题。

<ComboBox>
  <ComboBox.Resources>
    <Style TargetType="{x:Type TextBlock}">
      <Style.Triggers>
        <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ComboBoxItem}}" Value="True">
          <Setter Property="Foreground" Value="Red" />
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </ComboBox.Resources>
...
</ComboBox>
相关问题