I have an WPF application that contains a grid. The grid is split into 3 columns with the 3rd grid having zero width upon loading.
I have two datagrids in the other two
Using the correct DataTrigger
, this is totally possible. First, add the Trigger
to the UI element that you want to change... the ColumnDefinition
, not the Grid
:
<ColumnDefinition>
<ColumnDefinition.Style>
<Style TargetType="{x:Type ColumnDefinition}">
<Setter Property="Width" Value="10" />
<Style.Triggers>
<DataTrigger Binding="{Binding OrderSelected.Name}" Value="Mark">
<Setter Property="Width" Value="2*" />
</DataTrigger>
</Style.Triggers>
</Style>
</ColumnDefinition.Style>
</ColumnDefinition>
Next, don't set the Width
on the ColumnDefinition
element, but in the Style
instead. Otherwise the Width
on the ColumnDefinition
element will override the value set from the DataTrigger
.