WPF xaml将ComboBox背景颜色绑定到SelectedItem的颜色

时间:2013-02-26 19:06:17

标签: wpf xaml binding combobox selecteditem

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

对于绑定并发送CommandParameter的ComboBox Style,我有

    <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>

1 个答案:

答案 0 :(得分:0)

尝试:

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