textblock文字滚动效果

huihowie 2011-12-13 01:42:44
<VisualState x:Name="MouseOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ButtonDelete">
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
<DiscreteObjectKeyFrame KeyTime="0:0:0.001" Value="{x:Static Visibility.Visible}"/>
</ObjectAnimationUsingKeyFrames>

<ColorAnimation To="LightSlateGray" Duration="0:0:0.2" Storyboard.TargetProperty="(ListBoxItem.Background).(SolidColorBrush.Color)"/>

</Storyboard>
</VisualState>
要在这个storyboard里让ListBox里面的textblock实现文字滚动效果 应该怎么写?
...全文
433 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
huihowie 2011-12-13
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 fallincloud 的回复:]
一个例子:
自定义TextBlock如下:

C# code
public class TextBlockTest :TextBlock
{
TranslateTransform tt;
bool animated;
public TextBlockTest()
: base()
{……
[/Quote]
我以为在storyboard里像 <ColorAnimation To="LightSlateGray" Duration="0:0:0.2" Storyboard.TargetProperty="(ListBoxItem.Background).(SolidColorBrush.Color)"/>
写句话就搞定了 o(╯□╰)o
fallincloud 2011-12-13
  • 打赏
  • 举报
回复
一个例子:
自定义TextBlock如下:
public class TextBlockTest :TextBlock
{
TranslateTransform tt;
bool animated;
public TextBlockTest()
: base()
{
tt = new TranslateTransform();
this.RenderTransform = tt;
animated = false;
this.MouseEnter += new MouseEventHandler(TextBlockTest_MouseEnter);

}


void TextBlockTest_MouseEnter(object sender, MouseEventArgs e)
{
if (tt == null)
return;
if (animated)
return;

Duration duration = new Duration(TimeSpan.FromSeconds(0.5));

DoubleAnimation da = new DoubleAnimation(0,-30, duration);
da.AutoReverse = true;

tt.BeginAnimation(TranslateTransform.XProperty, da);
animated = true;


}




}

xaml很简单
<ListBox x:Name="ListBoxTest">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="50" Background="AliceBlue">
<local:TextBlockTest Text="{Binding}"></local:TextBlockTest>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

随便指定一个source:
string[] source = new string[] { "Alpha", "Beta","Crow"};
ListBoxTest.ItemsSource = source;
huihowie 2011-12-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 bunliney 的回复:]
如何滚动?上下/左右?循环滚动还是滚动一次?
[/Quote]
从右到左循环滚动
Bullatus 2011-12-13
  • 打赏
  • 举报
回复
如何滚动?上下/左右?循环滚动还是滚动一次?
huihowie 2011-12-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 fallincloud 的回复:]
先弄出个能运行的:遍历ListBox的Items找到你想要滚动的那个Textblock,然后让TextBlock执行动画,
接下来重构。
[/Quote]
具体该怎么搞 能贴个出来吗 大哥
fallincloud 2011-12-13
  • 打赏
  • 举报
回复
先弄出个能运行的:遍历ListBox的Items找到你想要滚动的那个Textblock,然后让TextBlock执行动画,
接下来重构。

8,734

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧