是否可以使用DataTrigger在WPF中设置RotateTransform的角度?如果是这样,怎么办?
最佳答案
当然,这样的事情应该可以工作
<TextBox>
<TextBox.Style>
<Style TargetType="TextBox">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text}"
Value="RotateMe">
<Setter Property="LayoutTransform">
<Setter.Value>
<RotateTransform Angle="45"/>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
另外,如果您已经设置了
LayoutTransform
,则可以使用EnterActions
的ExitActions
和DataTrigger
<TextBox>
<TextBox.LayoutTransform>
<RotateTransform Angle="0"/>
</TextBox.LayoutTransform>
<TextBox.Style>
<Style TargetType="TextBox">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text}"
Value="RotateMe">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:0"
To="45"
Storyboard.TargetProperty="(LayoutTransform).(RotateTransform.Angle)"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:0"
To="0"
Storyboard.TargetProperty="(LayoutTransform).(RotateTransform.Angle)"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
关于WPF RotateTransform DataTrigger,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10437024/