如果我按名称调用列表,我可以绑定到 Item 源,但是,我无法通过获取每个单独组合框上的项目计数来使绑定正常工作。
这是我想在 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>
Run Code Online (Sandbox Code Playgroud)
在绑定中包含RelativeSource组件:
<DataTrigger Binding="{Binding Path=Items.Count, RelativeSource={RelativeSource Self}}"
Value="0"
>
Run Code Online (Sandbox Code Playgroud)
您当前拥有它的方式绑定子系统将Items.Count在您设置为 ComboBox 的 DataContext 的任何内容上查找属性。