<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>
这段代码将App.IpInfoList
与ComboBox绑定。
IpInfo
类有一个bool类型的属性Enabled
。要求是当相应的IpInfo.Enable==false
时,设置ComboBoxItem.IsEnabled=false
(这样用户就无法选择它)。
我希望所有的代码都写在XAML中。