[英]How to make text moving Animation from bottom to top in UWP
How to animate the text from bottom to top in UWP. 如何在UWP中从底部到顶部为文本设置动画。 Is there any better way to trigger style properties in UWP.
有没有更好的方法来触发UWP中的样式属性。
How to make text moving Animation from bottom to top in UWP
如何使文本在UWP中从下至上移动动画
You could use DoubleAnimation
to approach, Please refer the following code. 您可以使用
DoubleAnimation
进行处理,请参考以下代码。
<Grid>
<Grid.Resources>
<Storyboard x:Name="MoveStoryboard">
<DoubleAnimation Storyboard.TargetName="Tbk"
Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)"
From="0" Windows10version1903:To="{x:Bind TbkY, Mode=TwoWay}" Duration="0:0:2">
</DoubleAnimation>
</Storyboard>
</Grid.Resources>
<TextBlock Loaded="Tbk_Loaded"
Name="Tbk"
Text="hello Nico"
VerticalAlignment="Bottom"
Visibility="Visible"
HorizontalAlignment="Center"
FontSize="22"
TextLineBounds="Full" >
<TextBlock.RenderTransform>
<CompositeTransform/>
</TextBlock.RenderTransform>
</TextBlock>
<Button Content="Move" Click="Button_Click"/>
</Grid>
Code Behind 背后的代码
private void Button_Click(object sender, RoutedEventArgs e)
{
MoveStoryboard.Begin();
}
public double TbkY { get; set; }
private void Tbk_Loaded(object sender, RoutedEventArgs e)
{
TbkY = -Tbk.ActualOffset.Y;
}
MVVM aproach to trigger story bord on datachange
MVVM方法引发数据变更故事
We can also trigger the story board on Data change. 我们还可以触发有关数据更改的故事板。 I tried the below code its works for me.
我尝试了下面的代码为我工作。 Use the below namespace before going to start .
在开始之前,请使用以下命名空间。 The nuget package will be availble on the link Microsoft.Xaml.Behaviors.Uwp.Managed
nuget包将在链接Microsoft.Xaml.Behaviors.Uwp.Managed上可用。
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
xmlns:Media ="using:Microsoft.Xaml.Interactions.Media"
<Page.Resources>
<Storyboard x:Name="MoveStoryboard">
<DoubleAnimation Storyboard.TargetName="txttext1"
Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)"
From="0" To="-200" Duration="0:0:2">
</DoubleAnimation>
</Storyboard>
</Page.Resources>
<Grid>
<TextBlock Text="Sample text to Animate">
<interactivity:Interaction.Behaviors>
<core:DataTriggerBehavior Binding ={Binding AnimateText} Value = true>
<Media:ControlStoryboardAction Storyboard="{StaticResource MoveStoryboard}"/>
</core:DataTriggerBehavior>
</interactivity:Interaction.Behaviors>
<TextBlock.RenderTransform>
<CompositeTransform/>
</TextBlock.RenderTransform>
</TextBlock>
</Grid>
I have changed the AnimateText property in ViewModel. 我已经更改了ViewModel中的AnimateText属性。 Whenever the property value is changed .The textblock will move bottom to top based on(- Y value that is To="-200").
无论何时更改属性值。文本块都将基于(-Y值为To =“-200”)从下到上移动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.