【问题标题】:WPF xaml binding ComboBox Background Color to SelectedItem's colorWPF xaml 将 ComboBox 背景颜色绑定到 SelectedItem 的颜色
【发布时间】:2013-02-26 19:06:16
【问题描述】:

我创建了一个 ComboBox 类来启用命令,我想将 ComboBox 的背景颜色作为命令参数发送。我想将 ComboBox 的背景绑定到 SelectedItem 的背景颜色。

对于绑定并发送我拥有的 CommandParameter 的 ComboBox 样式

    <Style x:Key="colorComboBox" TargetType="{x:Type local:ColorComboBox}" BasedOn="{StaticResource AnnotationToolbarComboBox}">
        <Setter Property="Background" Value="***SOME BINDING HERE???***"/>
        <Setter Property="Command" Value="{Binding ChangeColor, Mode=OneWay}"/>
        <Setter Property="CommandParameter" Value="{Binding Mode=OneWay, RelativeSource={RelativeSource Self}, Path=Background}"/>
        <Setter Property="CurrentColor" Value="{Binding CurrentColor, Mode=OneWay}"/>
    </Style>

对于带有 ComboBoxItems 的 ComboBox。我想绑定到这些 ComboBoxItems 的背景。

        <local:CommandableComboBox Background="Red">
            <ComboBoxItem Width="50" Height="50" Background="Blue"/>
            <ComboBoxItem Width="50" Height="50" Background="Green"/>
            <ComboBoxItem Width="50" Height="50" Background="Red"/>
        </local:CommandableComboBox>

【问题讨论】:

    标签: wpf xaml binding combobox selecteditem


    【解决方案1】:

    试试:

    <Setter Property="Background" Value="{Binding SelectedItem.Background, RelativeSource={RelativeSource Self}}"/>
    

    【讨论】:

      猜你喜欢
      • 2010-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-06
      • 1970-01-01
      • 2016-10-27
      • 2016-01-23
      • 1970-01-01
      相关资源
      最近更新 更多