<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>
This code has binded App.IpInfoList
to ComboBox.
IpInfo
class has a bool property Enabled
. The requirement is that set ComboBoxItem.IsEnabled=false
(so that users can't select it) when corresponding IpInfo.Enable==false
.
I hope all code is written in XAML.
<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>
It binds ComboBoxItem.IsEnabled
property to your IpInfo.Enabled
property
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With