WPF Trigger Binding: What's the best way to bind an enum value to visiblity?
I use data triggers for this. It looks something like this;
<Style TargetType="DockPanel" x:Key="ViewStyle1">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ViewStyle}" Value="ViewStyle1">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
Then I create a DockPanel
for each view style, and whenever the ViewStyle
property changes, the appropriate view displays.
Like a lot of WPF, it really depends on your taste. Here are a few choices.
You could create three IValueConverter that converts the value of the View property to a Visibility (or use the enum name as a ConverterParameter and create one converter).
You could create three new properties called "StandardViewIsVisible", "FluidViewIsVisible", and "OtherViewIsVisible" that get updated when the View property changes. These properties would be of return type Visibility. This is decidedly more of an "MVVM" way of doing things, even if you aren't using a ViewModel.
You could use a DataTrigger that sets the appropriate grid Visible or Collapsed based on the current value of the View property.