使用 VisualStateManager 更改按钮样式
Change button style with VisualStateManager
我正在开发通用 Windows 应用程序。
我想在不同状态下更改按钮的样式,但我想不通(我是新手)
这是我的视觉状态组
<VisualStateGroup x:Name="StartStopTimer">
<VisualState x:Name="Start">
</VisualState>
<VisualState x:Name="Stop">
<VisualState.Setters>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
我有两个样式设置,名为 StartButtonStyle
和 StopButtonStyle
。
所以我想在 Stop
视觉状态下将按钮样式更改为 StopButonStyle
,在 Start
视觉状态下将按钮样式更改为 StartButtonStyle
。
我该怎么做?我尝试在 Expression Blend 中启用记录,但它没有对我的视觉状态应用任何内容。
你在这里:
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="StartStopTimer">
<VisualState x:Name="Start">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="TestButton"
Storyboard.TargetProperty="Style">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource StartButtonStyle}">
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Stop">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="TestButton"
Storyboard.TargetProperty="Style">
<DiscreteObjectKeyFrame KeyTime="0"
Value="{StaticResource StopButtonStyle}">
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
当然你需要在资源中定义你的样式,例如在页面资源中。
请不要忘记将我的回复标记为答案。
我正在开发通用 Windows 应用程序。
我想在不同状态下更改按钮的样式,但我想不通(我是新手)
这是我的视觉状态组
<VisualStateGroup x:Name="StartStopTimer">
<VisualState x:Name="Start">
</VisualState>
<VisualState x:Name="Stop">
<VisualState.Setters>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
我有两个样式设置,名为 StartButtonStyle
和 StopButtonStyle
。
所以我想在 Stop
视觉状态下将按钮样式更改为 StopButonStyle
,在 Start
视觉状态下将按钮样式更改为 StartButtonStyle
。
我该怎么做?我尝试在 Expression Blend 中启用记录,但它没有对我的视觉状态应用任何内容。
你在这里:
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="StartStopTimer">
<VisualState x:Name="Start">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="TestButton"
Storyboard.TargetProperty="Style">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource StartButtonStyle}">
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Stop">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="TestButton"
Storyboard.TargetProperty="Style">
<DiscreteObjectKeyFrame KeyTime="0"
Value="{StaticResource StopButtonStyle}">
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
当然你需要在资源中定义你的样式,例如在页面资源中。
请不要忘记将我的回复标记为答案。