简体   繁体   English

如何使文本在UWP中从下至上移动动画

[英]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.

相关问题 如何在 uwp 的滚动查看器中从底部到顶部垂直偏移? - How to get vertical offset from bottom to top in scrollviewer in uwp? 如何在WPF动画中从下至上显示窗口 - How to show window from bottom to top in wpf in animation c#uwp动画使文本闪烁 - c# uwp animation make text flicker 如何使FlipView具有缓慢移动的标题? 超人 - How to make FlipView with slow moving headers? UWP 如何将文本添加到文本框,从下到上 - How to add text to a textbox, starting from bottom to top 在多行 tabcontrol 中从下到上移动标签页时跳动 - Tabpages are jumping when moving them from bottom to top in multiline tabcontrol 在具有可调整大小的顶部行的网格中,如何在不移动底部行的绝对位置的情况下调整顶部行的大小? - In a grid with a top resizable row, how can I resize the top row without moving the absolute position of the bottom rows? 如何以统一C#使敌人从屏幕顶部移动到屏幕底部? - How do i make enemy move from top to bottom of screen in unity c#? 如何在导出到垂直(从下到上)时更改DevExpress MVC Grid标题文本 - How to change DevExpress MVC Grid header text on export to vertical (from bottom to top) 在其他元素之后移动特定元素但不移动到顶部或底部 - Moving specific elements after others but not to top or bottom
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM