我正在ControlTemplate
处理Button
这是我当前的代码,它改变了按钮的颜色。
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1.Styles">
<ControlTemplate x:Key="ButtonBrushAnimation" TargetType="Button">
<Grid >
<TextBlock x:Name="textBlock" Width="80" Height="30" Text="AAA" />
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<!--Take one half second to transition to the PointerOver state.-->
<VisualTransition To="PointerOver" GeneratedDuration="0:0:0.5"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="PointerOver">
<Storyboard>
<ColorAnimation Storyboard.TargetName="ButtonBrush"
Storyboard.TargetProperty="Color" To="Red" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.Background>
<SolidColorBrush x:Name="ButtonBrush" Color="Green"/>
</Grid.Background>
</Grid>
</ControlTemplate>
</ResourceDictionary>
我想更改textBlock
事件PointerOver
控件的文字属性
我该怎么办?
谢谢!
答案 0 :(得分:1)
将StringAnimationUsingKeyFrames
添加到Storyboard
,如下所示:
<Storyboard>
<ColorAnimation Storyboard.TargetName="ButtonBrush" Storyboard.TargetProperty="Color" To="Red" />
<StringAnimationUsingKeyFrames Storyboard.TargetName="textBlock" Storyboard.TargetProperty="Text">
<DiscreteStringKeyFrame Value="BBB" KeyTime="0:0:0" />
</StringAnimationUsingKeyFrames>
</Storyboard>
您可以根据更改文本的具体时间设置KeyTime
属性值。