A failed XAML attempt here – I’m obviously doing something stupid with the Style/Setter syntax. I just want to flip an element based on some bindings by setting the ScaleX and ScaleY properties of a ScaleTransform from a DataTrigger. Setter.Property obviously doesn’t support a property path, but how can I get round this? I can’t set the whole RenderTransform property because ScaleX and ScaleY are independent. Any ideas?
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<TextBlock FontSize="50" RenderTransformOrigin=".5,.5">
<TextBlock.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, ElementName=FlipX}" Value="True">
<Setter Property="RenderTransform.ScaleX" Value="-1"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsChecked, ElementName=FlipY}" Value="True">
<Setter Property="RenderTransform.ScaleY" Value="-1"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
<TextBlock.RenderTransform>
<ScaleTransform/>
</TextBlock.RenderTransform>
Hello World
</TextBlock>
<CheckBox Name="FlipX">Flip x</CheckBox>
<CheckBox Name="FlipY">Flip y</CheckBox>
</StackPanel>
</Page>
Setters work on elements, and
Transformdoesn’t derive fromUIElement, so I don’t think you’re going to be able to do this using a style.I’d fix this in the view model: implement boolean
FlipXandFlipYproperties, and exposeScaleXandScaleYproperties that theScaleTransformcan bind to.