2014-09-12 56 views
1

如果我按名称调用列表,我可以绑定到Item源,但是,我无法通过获取每个单独组合框上的项目计数来一般工作。如何使用样式和DataTrigger绑定到XAML中项目源的计数?

这是我想要在XAML中做的事情。我需要更改此绑定才能工作?

<Grid.Resources> 
    <Style TargetType="ComboBox">        
    <Style.Triggers> 
     <DataTrigger Binding="{Binding Path=Items.Count}" Value="0"> 
      <Setter Property="IsEnabled" Value="False"></Setter> 
     </DataTrigger> 
    </Style.Triggers> 
    </Style> 
</Grid.Resources> 

    <ComboBox 
    ItemsSource="{Binding MyList}"    
    SelectedItem="{Binding SelectedElement}" 
    ItemTemplate="{StaticResource MyTemplate}"> 
     </ComboBox> 

回答

3

包括在你的绑定RelativeSource组件:

<DataTrigger Binding="{Binding Path=Items.Count, RelativeSource={RelativeSource Self}}" 
      Value="0" 
      > 

您当前拥有它的方式绑定子系统将寻求在任何您已设置为组合框的的DataContext Items.Count财产。

+2

谢谢你,完美的工作。 – Bob 2014-09-12 13:40:56

相关问题