I have a user control (NameField
). Within it I have a stackpanel containing 3 Grids: StandardView
, FluidView
, OtherView
. Within the code-behind I have a DependencyProperty
called View
of type NameFieldView
(enum
). The enum contains STANDARD
, FLUID
, OTHER
.
I think I have to create a converter, but I'm not sure if that's necessary. I basically want to make it so that the only visible grid is the one that matches the enum value... that is, if View = NameFieldView.STANDARD
then the Grid named StandardView
is visible and the other two are not.
Also, I'm not sure if this should be part of Grid.Resources / Style
or Grid.Triggers
?
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.
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