TextBlock滚动条


<ScrollViewer Name="scrollViewer">
<TextBlock TextWrapping="Wrap" ScrollViewer.VerticalScrollBarVisibility="Auto" Name="txtContent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ></TextBlock>
</ScrollViewer>





<ScrollViewer VerticalScrollBarVisibility="Auto" MaxHeight="90" Width="130">
<TextBlock Margin="0 5 0 5" TextWrapping="Wrap" Name="txtAddress"></TextBlock>
</ScrollViewer>
您可以使用以下示例代码来创建WPF TextBlock滚动动画: ```XAML <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <ScrollViewer VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Disabled"> <TextBlock x:Name="myTextBlock" TextWrapping="Wrap" FontSize="24" Text="This is some sample text that will be scrolled horizontally."/> </ScrollViewer> </Grid> </Window> ``` 在代码中,我们使用了一个ScrollViewer控件来包含TextBlock,并将其水平和垂直滚动条的可见性设置为禁用。这将使TextBlock只能在ScrollViewer内滚动。 接下来,我们需要在代码中添加动画。我们将使用DoubleAnimation来使TextBlock水平滚动。以下是示例代码: ```C# using System.Windows; using System.Windows.Controls; using System.Windows.Media.Animation; namespace WpfApplication1 { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DoubleAnimation animation = new DoubleAnimation(); animation.From = 0; animation.To = -myTextBlock.ActualWidth; animation.RepeatBehavior = RepeatBehavior.Forever; animation.Duration = new Duration(new TimeSpan(0, 0, 10)); //设置滚动时间 TranslateTransform trans = new TranslateTransform(); myTextBlock.RenderTransform = trans; trans.BeginAnimation(TranslateTransform.XProperty, animation); } } } ``` 在代码中,我们创建了一个DoubleAnimation对象,并将其From和To属性设置为0和负TextBlock宽度,以使TextBlock水平滚动。我们还将RepeatBehavior属性设置为Forever,以使动画永远重复。最后,我们设置了动画的持续时间,并将其应用于TextBlock的RenderTransform属性。这将使TextBlock滚动。 运行应用程序后,您将看到TextBlock在屏幕上水平滚动。您可以调整动画的持续时间,以使滚动速度更快或更慢。您还可以使用其他动画属性来自定义动画。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值