【发布时间】:2020-04-03 09:30:37
【问题描述】:
在代码中
private void TickerGrid_Loaded(object sender, RoutedEventArgs e)
{
double height = TickerCanvas.ActualHeight - TextBoxMarquee.ActualHeight;
TextBoxMarquee.Margin = new Thickness(0, height / 2, 0, 0);
DoubleAnimation doubleAnimation = new DoubleAnimation();
doubleAnimation.From = -TextBoxMarquee.ActualWidth; // -277
doubleAnimation.To = TickerCanvas.ActualWidth; //524
doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
doubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(5));
TextBoxMarquee.BeginAnimation(Canvas.RightProperty, doubleAnimation);
}
在 Xaml 中
<Grid x:Name="TickerGrid" Grid.Row="2" Loaded="TickerGrid_Loaded" Background="#2B2F3B" >
<Canvas ClipToBounds="True" Name="TickerCanvas" Background="Transparent">
<TextBlock ClipToBounds="True" Name="TextBoxMarquee" Background="#2B2F3B">
<TextBlock.Inlines>
<Run FontWeight="Bold" Foreground="#55CFE3" FontSize="14" Text="This is WPF Ticker Title." />
<Run FontSize="13" Foreground="#FFFFFF" Text="This is Content text." />
</TextBlock.Inlines>
</TextBlock>
</Canvas>
</Grid>
我确实做了一个ticker,但是我不明白Canvas从“From”到“To”的移动原理。
【问题讨论】:
-
我不明白这个问题。你对什么感到困惑?