使用Converter实现控件的动态显隐

效果如图:

根据下拉框fieldTypeComboBox,控制其他控件的显隐

关键代码

<ComboBox Grid.Column="1" Grid.Row="2" DataContext="{Binding FieldTypeEnumInfos}" ItemsSource="{Binding }" Name="fieldTypeComboBox" DisplayMemberPath="Description" SelectedValuePath="Value"></ComboBox>
<CheckBox Grid.Column="1" Grid.Row="3" IsChecked="{Binding IsUniqueKey,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding SelectedItem,ElementName=fieldTypeComboBox,Converter={StaticResource EditFieldVisibilityConverter},ConverterParameter=IsUniqueKey}"></CheckBox>

示例代码

Converters

原文地址:https://www.cnblogs.com/Lulus/p/13157894.html