0

Here is the Code snippet which i want to use in Resource Section

 <UserControl.Resources> 
  <MultiBinding Converter="{StaticResource ResourceKey=EnableConference}" 
                  x:Key="EnableifConferenceIsNotNullAndIsStarted">
        <Binding Path="SelectedConference" Mode="OneWay"/>
        <Binding Path="SelectedConference.ConferenceStatus" Mode="OneWay"/>
  </MultiBinding>
</UserControl.Resources>

and i want to use this in a control like the fallowing

<ComboBox><ComboBox.IsEnabled><StaticResource ResourceKey="EnableifConferenceIsNotNullAndIsStarted"></ComboBox.IsEnabled></ComboBox>

it is not allowing this and saying as invalid type in the usage

4

1 回答 1

2

错误信息很清楚:

不能在“MainWindow”类型的“资源”属性上设置“MultiBinding”。只能在 DependencyObject 的 DependencyProperty 上设置“MultiBinding”。

但是,您可以在 ComboBoxes 的样式中声明绑定:

<Style TargetType="ComboBox" x:Key="MyComboBoxStyle">
    <Setter Property="IsEnabled">
        <Setter.Value>
            <MultiBinding Converter="{StaticResource ResourceKey=EnableConference}">
                <Binding Path="SelectedConference" Mode="OneWay"/>
                <Binding Path="SelectedConference.ConferenceStatus" Mode="OneWay"/>
            </MultiBinding>
        </Setter.Value>
    </Setter>
</Style>

并在适用的情况下使用它:

<ComboBox Style="{StaticResource MyComboBoxStyle}"/>

当然不一定需要将其放入 Style 中。您也可以直接将 MultiBinding 分配给IsEnabledComboBox 的属性:

<ComboBox>
    <ComboBox.IsEnabled>
        <MultiBinding Converter="{StaticResource ResourceKey=EnableConference}">
            <Binding Path="SelectedConference" Mode="OneWay"/>
            <Binding Path="SelectedConference.ConferenceStatus" Mode="OneWay"/>
        </MultiBinding>
    </ComboBox.IsEnabled>
</ComboBox>
于 2013-01-14T12:53:15.160 回答