如果我按名称调用列表,我可以绑定(bind)到项目源,但是,我无法通过获取每个单独组合框中的项目计数来使绑定(bind)正常工作。
这是我想在 XAML 中执行的操作。我需要更改什么才能使此绑定(bind)正常工作?
<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>
最佳答案
包括 RelativeSource绑定(bind)中的组件:
<DataTrigger Binding="{Binding Path=Items.Count, RelativeSource={RelativeSource Self}}"
Value="0"
>
按照您当前的方式,绑定(bind)子系统将在您设置为 ComboBox 的 DataContext 的任何内容上查找 Items.Count
属性。
关于c# - 如何使用样式和 DataTrigger 绑定(bind)到 XAML 中的项目源计数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25809394/