I would like to enlarge (i.e. ScaleTransform) a whole grid depending on a property of my custom class.
My Grid
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="2*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Viewbox Style="{StaticResource InvViewBoxStyle}" Grid.Column="1" Grid.Row="0">
<TextBlock Style="{StaticResource InvBoxTextStyle}" Text="{Binding BoxId}" />
</Viewbox>
<Viewbox Style="{StaticResource InvViewBoxStyle}" Grid.Column="1" Grid.Row="1" >
<TextBlock Style="{StaticResource InvBoxTextStyle}" Text="{Binding ProdNr}" />
</Viewbox>
</Grid>
This is the style I used. The problem is, there is no scaling to be seen at all. I tested the code with another animation (changing the background color) which worked fine.
<Style x:Key="InvViewBoxStyle" TargetType="Viewbox">
<Setter Property="LayoutTransform">
<Setter.Value>
<ScaleTransform />
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding IsReadyToUnload}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="LayoutTransform.ScaleX" To="2" Duration="0:0:0.5" />
<DoubleAnimation Storyboard.TargetProperty="LayoutTransform.ScaleY" To="2" Duration="0:0:0.5" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
Could you give me any hints on how to achieve the correct scaling behavior?
Try attaching this to your
ViewBox.Also try changing your animation to this, name your first
ViewBoxviewbox.Sorry, didn’t see that you are using
LayoutTransform. You should useRenderTransforminstead, try changing theSetter Propertyas well as theStoryboard.TargetPropertytoRenderTransformand it should work.Also if you want to keep the
LayoutTransformyou can try changing yourGridto aCanvas, that might work too.