簡體   English   中英

具有TranslateTransform的WPF故事板

[英]WPF Storyboard with TranslateTransform

我有一個情節提要,例如

<Storyboard x:Key="NewsFlow">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" 
                                       Storyboard.TargetName="TextBlock" 
                                       RepeatBehavior="Forever" AutoReverse="True">
            <EasingDoubleKeyFrame KeyTime="0:0:0" Value="-80"/>
            <EasingDoubleKeyFrame KeyTime="0:0:2" Value="80"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>

和網格

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="1*" />
        <RowDefinition Height="100" />
        <RowDefinition Height="1*" />
    </Grid.RowDefinitions>
    <Border Grid.Row="1" Background="BlanchedAlmond"></Border>
    <TextBlock Grid.Row="1" Text="News" FontSize="40" HorizontalAlignment="Center" ></TextBlock>

</Grid>

Grid.Row =“ 1”是新聞查看區域(黃線)

但是Storyboard忽略了Grid.RowDefinitions之類的圖片 在此處輸入圖片說明

我要這樣

在此處輸入圖片說明

如果創建情節提要,則應如下所示:

    <Storyboard x:Key="NewsFlow">
        <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" 
                                       Storyboard.TargetName="TextBlock" 
                                       RepeatBehavior="Forever" AutoReverse="True">
            <EasingThicknessKeyFrame KeyTime="0:0:0" Value="0,0,0,150"/>
            <EasingThicknessKeyFrame KeyTime="0:0:1" Value="0,0,0,0"/>
            <EasingThicknessKeyFrame KeyTime="0:0:2" Value="0, 150,0,0"/>
        </ThicknessAnimationUsingKeyFrames>
    </Storyboard>

在此處輸入圖片說明

但是Margin落后於TranslateTransform。 和Textblock的另一端在播放動畫時壞了

謝謝,問候

<Window.Resources>
    <Storyboard x:Key="NewsFlow">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Height" 
                                       Storyboard.TargetName="News" 
                                       RepeatBehavior="Forever" AutoReverse="True">
            <EasingDoubleKeyFrame KeyTime="0:0:00" Value="-80"/>
            <EasingDoubleKeyFrame KeyTime="0:0:02" Value="80"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
</Window.Resources>
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="100" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Border Grid.Row="1" Background="BlanchedAlmond"/>
    <TextBlock Grid.Row="1" x:Name="News" Text="News" FontSize="40" HorizontalAlignment="Center">
        <TextBlock.Triggers>
            <EventTrigger RoutedEvent="Loaded">
                <BeginStoryboard Storyboard="{StaticResource NewsFlow}"/>
            </EventTrigger>                              
        </TextBlock.Triggers>
    </TextBlock>
</Grid>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM