I have a grid whose rows need to be resized dynamically based on the view model. I\'d like to do something like the following:
I think the only problem with your Xaml code is that you're overwriting the DataTrigger by setting Height explictly on the RowDefinition
. Try with using a Setter instead
<RowDefinition>
<RowDefinition.Style>
<Style>
<Setter Property="RowDefinition.Height" Value="2*"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=ShowSection}" Value="True">
<Setter Property="RowDefinition.Height" Value="2*"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=ShowSection}" Value="False">
<Setter Property="RowDefinition.Height" Value="0"/>
</DataTrigger>
</Style.Triggers>
</Style>
</RowDefinition.Style>
</RowDefinition>
I know this post is 3 years old, but still it might help someone.
<RowDefinition>
<RowDefinition.Style>
<Style TargetType="RowDefinition">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=ShowSection}" Value="True">
<Setter Property="Height" Value="2*"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=ShowSection}" Value="False">
<Setter Property="Height" Value="0"/>
</DataTrigger>
</Style.Triggers>
</Style>
</RowDefinition.Style>
</RowDefinition>
I was in same situation, i managed to get it working by setting TargetType to RowDefinition.