gpt4 book ai didi

wpf - 使用 DataTrigger 设置 ScaleTransform 的属性

转载 作者:行者123 更新时间:2023-12-04 17:27:08 26 4
gpt4 key购买 nike

这里的 XAML 尝试失败 - 我显然在用 Style 做一些愚蠢的事情/Setter句法。我只想通过设置 ScaleX 来翻转基于某些绑定(bind)的元素和 ScaleY ScaleTransform 的属性来自 DataTrigger . Setter.Property显然不支持属性路径,但是我该如何解决呢?我无法设置整个RenderTransform属性,因为 ScaleXScaleY是独立的。有任何想法吗?

<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>

最佳答案

你可以使用:

<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsChecked, ElementName=FlipX}" Value="True" />
<Condition Binding="{Binding IsChecked, ElementName=FlipY}" Value="True" />
</MultiDataTrigger.Conditions>
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="-1" ScaleY="-1" />
</Setter.Value>
</Setter>
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsChecked, ElementName=FlipX}" Value="True" />
<Condition Binding="{Binding IsChecked, ElementName=FlipY}" Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="-1" ScaleY="1" />
</Setter.Value>
</Setter>
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsChecked, ElementName=FlipX}" Value="False" />
<Condition Binding="{Binding IsChecked, ElementName=FlipY}" Value="True" />
</MultiDataTrigger.Conditions>
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="1" ScaleY="-1" />
</Setter.Value>
</Setter>
</MultiDataTrigger>
</Style.Triggers>

关于wpf - 使用 DataTrigger 设置 ScaleTransform 的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7110491/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com