我想通过复选框激活转换。
在我的示例中,我有两个复选框,它们应该分别在 x 或 y 方向上交换标签中的文本。
如果没有代码,这可能吗?
到目前为止,这是我的 xaml:
<Window x:Class="WpfVideoTest.InversionTestWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="InversionTestWindow" Height="300" Width="300">
<DockPanel>
<CheckBox DockPanel.Dock="Bottom" IsChecked="{Binding InvertX}">Invert X</CheckBox>
<CheckBox DockPanel.Dock="Bottom" IsChecked="{Binding InvertY}">Invert Y</CheckBox>
<Label Content="Text to invert" FontSize="40" x:Name="TextToInvert">
<Label.RenderTransform>
<TransformGroup>
<!-- transformations to swap in x direction -->
<ScaleTransform ScaleX="-1" />
<TranslateTransform X="{Binding ActualWidth, ElementName=TextToInvert}" />
<!-- transformations to swap in y direction -->
<ScaleTransform ScaleY="-1" />
<TranslateTransform Y="{Binding ActualHeight, ElementName=TextToInvert}" />
</TransformGroup>
</Label.RenderTransform>
</Label>
</DockPanel>