我希望 ComboBox 的 XAML 根据它是否有项目来处理它自己的 IsEnabled 属性。如果后面代码中的 DataTable 返回 Items, id 就像要启用的 ComboBox ,否则如果没有添加任何 Items ,它会保留或成为禁用的控件。这是可能吗?
我当前的组合框设置:
<ComboBox x:Name="ImportDate"
DisplayMemberPath="FileDate"
SelectedValuePath="ID"
ItemsSource="{Binding Mode=OneWay}"
SelectedIndex="0"
Style="{DynamicResource sanComboBox_Standard}" />
Run Code Online (Sandbox Code Playgroud)
如果您希望在ComboBox有项目时启用,并在没有项目时禁用,您可以绑定IsEnabled到HasItems属性:
<ComboBox x:Name="ImportDate"
DisplayMemberPath="FileDate"
SelectedValuePath="ID"
ItemsSource="{Binding Mode=OneWay}"
SelectedIndex="0"
Style="{DynamicResource sanComboBox_Standard}"
IsEnabled="{Binding HasItems, RelativeSource={RelativeSource Self}}" />
Run Code Online (Sandbox Code Playgroud)