So I've got a grid that needs to change it's margin based on flag in the VM. Seems like datatriggers is the right way to handle this.
So I set this up:
<Grid x:Name="myGrid" Grid.Row="1" Margin="30,0">
<Grid.Style>
<Style TargetType="Grid">
<Style.Triggers>
<DataTrigger Binding="{Binding UI_Preferences.RightPanelPinned}" Value="true" >
<Setter Property="Margin" value="200" />
</DataTrigger>
<DataTrigger Binding="{Binding UI_Preferences.LeftPanelPinned}" Value="true" >
<Setter Property="Margin" value="200" />
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
</Grid>
Which works, but I can't figure out how to modify just the left or right margins individually.
A margin is actually a Thickness
element, so you can do it like this:
EDIT - have added condition where bot are set:
<Grid x:Name="myGrid" Grid.Row="1" Margin="30,0">
<Grid.Style>
<Style TargetType="Grid">
<Style.Triggers>
<DataTrigger Binding="{Binding UI_Preferences.RightPanelPinned}" Value="true" >
<Setter Property="Margin">
<Setter.Value>
<Thickness Left="200"/>
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding UI_Preferences.LeftPanelPinned}" Value="true" >
<Setter Property="Margin">
<Setter.Value>
<Thickness Right="200"/>
</Setter.Value>
</Setter>
</DataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding UI_Preferences.LeftPanelPinned}" Value="true" />
<Condition Binding="{Binding UI_Preferences.RightPanelPinned}" Value="true" />
</MultiDataTrigger.Conditions>
<Setter Property="Margin">
<Setter.Value>
<Thickness Right="200" Left="200"/>
</Setter.Value>
</Setter>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
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