0

リソースセクションで使用したいコードスニペットは次のとおりです

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

そして、これをFallowingのようなコントロールで使用したい

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

これは許可されておらず、使用法で無効なタイプと言っています

4

1 に答える 1

2

エラーメッセージは非常に明確です:

'MainWindow' 型の 'Resources' プロパティに 'MultiBinding' を設定することはできません。「MultiBinding」は、DependencyObject の DependencyProperty でのみ設定できます。

ただし、ComboBox の Style でバインディングを宣言することもできます。

<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 に答える