2016-07-20 11 views
1

マルチバインドを再利用し、this solutionを使用しようとしましたが、セッタープロパティからIsEnabledに到達できないようです。アプリケーションリソースで定義されたマルチバインディングにアクセスする方法

は、だから私は、このアプローチを試してみましたが、無葉巻:

App.xaml

<Application x:Class="Test.App" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:model="clr-namespace:Test.MODEL" 
     StartupUri="MainWindow.xaml"> 
<Application.Resources>  
    <view:BooleanConverter x:Key="BooleanConverter" /> 
    <view:BooleanMultiConverter x:Key="BooleanMultiConverter" /> 
    <MultiBinding x:Key="OnOffBinding" Converter="{StaticResource BooleanMultiConverter}" ConverterParameter="OR"> 
      <Binding Path="model:CustomerIsDefined" Converter="{StaticResource BooleanConverter}" /> 
      <Binding Path="model:CustomerIsConfirmed" Converter="{StaticResource BooleanConverter}" /> 
    </MultiBinding> 
</Application.Resources> 

MainWindow.xaml>これらの二つの試みはコンパイルされません。

<TextBox IsEnabled="{StaticResource OnOffBinding}"/> 
<TextBox IsEnabled="{MultiBinding {StaticResource OnOffBinding}}" /> 

何か案は?

編集: Funcsの回答を受け入れると、これは既にリンクされたスレッドで回答されているようです。申し訳ありません..

答えて

2

は注意TargetType="Control"は、それが一般的な作りのスタイル

<Application.Resources> 
    <view:BooleanConverter x:Key="BooleanConverter" /> 
    <view:BooleanMultiConverter x:Key="BooleanMultiConverter" /> 
    <Style x:Key="ControlEnabler" TargetType="Control"> 
     <Setter Property="IsEnabled"> 
      <Setter.Value> 
       <MultiBinding x:Key="OnOffBinding" Converter="{StaticResource BooleanMultiConverter}" ConverterParameter="OR"> 
        <Binding Path="model:CustomerIsDefined" Converter="{StaticResource BooleanConverter}" /> 
        <Binding Path="model:CustomerIsConfirmed" Converter="{StaticResource BooleanConverter}" /> 
       </MultiBinding> 
      </Setter.Value> 
     </Setter> 
    </Style> 
</Application.Resources> 

MainWindow.xaml

<TextBox Style="{StaticResource ControlEnabler}"/> 

でそれをラップ試してみてください。

+0

Style = "{StaticResource ControlEnabler}"はキャストを無効にします。私が書いたように、私はすでにこのアプローチを試みました。あなたがローカルレベルでこれをやろうとすると、SettersプロパティからIsEnabledにアクセスできないことがわかります – noontz

+0

@noontzうまくいきました。 MultiBindingはブール値を返す必要があります。 – Funk

+0

努力をいただきありがとうございます。 BooleanMultiConverterのコードを教えてください。私はブール値を返しますが、あなたのapp.xamlスニペットをコンパイルできません:x:Key = "OnOffBinding"の部分にエラーMC3032があります – noontz

関連する問題