Xaml 将集合绑定到WPF组合框并禁用某些项

Xaml 将集合绑定到WPF组合框并禁用某些项,xaml,binding,Xaml,Binding,此代码已将App.ipinfo绑定到组合框 IpInfo类已启用bool属性。要求在对应的IpInfo.Enable==false时设置comboxItem.IsEnabled=false(这样用户就不能选择它) 我希望所有代码都是用XAML编写的。 <Window.Resources> <DataTemplate x:Key="IpInfoTemplate"> <DockPanel> <TextBlock

此代码已将App.ipinfo绑定到组合框

IpInfo
类已启用bool属性
。要求在对应的
IpInfo.Enable==false
时设置
comboxItem.IsEnabled=false
(这样用户就不能选择它)

我希望所有代码都是用XAML编写的。


<Window.Resources>
    <DataTemplate x:Key="IpInfoTemplate">
        <DockPanel>
            <TextBlock Text="{Binding Path=InterfaceName}" DockPanel.Dock="Left" Margin="0,0,10,0" />
            <TextBlock Text="{Binding Path=Address}"/>
        </DockPanel>
    </DataTemplate>
</Window.Resources>

<ComboBox ItemTemplate="{StaticResource IpInfoTemplate}"
      ItemsSource="{Binding Source={x:Static WpfApplication1:App.IpInfoList}, Mode=OneWay}">    
</ComboBox>
它将
ComboBoxItem.IsEnabled
属性绑定到您的
IpInfo.Enabled
属性

<ComboBox ItemTemplate="{StaticResource IpInfoTemplate}" 
          ItemsSource="{Binding Source={x:Static WpfApplication1:App.IpInfoList}, Mode=OneWay}">
    <ComboBox.ItemContainerStyle>
        <Style TargetType="{x:Type ComboBoxItem}">
            <Setter Property="IsEnabled" Value="{Binding Enabled}"/>
        </Style>
    </ComboBox.ItemContainerStyle>
</ComboBox>