2013-01-14 22 views
0

這裏是代碼片段,我想在資源科是否可以在資源中聲明MultiBindning並在控件中使用它?

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

使用,我想在控制使用該像休耕

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

它不允許這一點,並說爲無效在使用

回答

2

差錯報文類型是相當清楚的:

A「Mul的tiBinding'不能在 'MainWindow'類型的'Resources'屬性上設置。 'MultiBinding'只能在DependencyObject的DependencyProperty 上設置。

但是你可以聲明在樣式組合框的結合:

<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}"/> 

當然,不一定需要把這變成了一種風格。你還可直接分配MultiBinding到ComboBox的IsEnabled屬性:

<ComboBox> 
    <ComboBox.IsEnabled> 
     <MultiBinding Converter="{StaticResource ResourceKey=EnableConference}"> 
      <Binding Path="SelectedConference" Mode="OneWay"/> 
      <Binding Path="SelectedConference.ConferenceStatus" Mode="OneWay"/> 
     </MultiBinding> 
    </ComboBox.IsEnabled> 
</ComboBox> 
+0

是否有可能以任何其他方式比風格,因爲我們可能已經分配給這些控件的一些風格 –

相關問題