【发布时间】:2014-02-10 10:53:33
【问题描述】:
我正在使用 Itemcontrol 创建一个 Windows 8 应用程序并绑定数据列表以显示新闻。我需要在 HTML 中创建类似于新闻自动收报机的动画,如链接所示:http://coolcarousels.frebsite.nl/c/9/ 我将如何实现这一目标?
代码:
<ItemsControl x:Name="lstdata" >
<ItemsControl.ItemTemplate >
<DataTemplate >
<!--Date-->
<StackPanel Orientation="Vertical" Margin="10,0" HorizontalAlignment="Left" VerticalAlignment="Center" >
<TextBlock HorizontalAlignment="Left" Text="{Binding Path=ModifedDate,Converter={StaticResource DatetimeToStringFormatConverter}}" VerticalAlignment="Top" Grid.Row="1" FontFamily="Segoe UI" FontWeight="Bold" FontSize="13.33" />
<TextBlock Margin="0,0,0,0" Text="{Binding Path=Title , Mode=TwoWay}" Grid.Row="3" HorizontalAlignment="Left" VerticalAlignment="Top" FontFamily="Segoe UI" FontSize="13.33" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
var newsViewModel = new NewsViewModel();
await newsViewModel.GetNews();
lstdata.ItemsSource = newsViewModel.NewsList;
动画:
FlipViewNews.RenderTransform = new TranslateTransform();
DoubleAnimation animateX = new DoubleAnimation();
animateX.From = 0;
animateX.To = 200;
animateX.Duration = TimeSpan.FromMilliseconds(400);
Storyboard.SetTarget(animateX, FlipViewNews.RenderTransform);
Storyboard.SetTargetProperty(animateX, "TranslateTransform.X");
Storyboard story = new Storyboard();
story.Children.Add(animateX);
story.RepeatBehavior = RepeatBehavior.Forever;
story.Begin();
我已经能够制作动画了。上面的代码正在运行,唯一的问题是我需要在绑定所有项目后获取 ItemsControl 实际宽度。我怎样才能得到它,以便我可以在 HTML 中创建一个类似于 marquee 的动画??
【问题讨论】:
-
您需要在 Xaml 或 C# 中使用一些动画代码。您能否编辑问题以包含您尝试过的内容?如果您使用过 WinJs+HTML,那么克隆会更容易。 :)
-
我已经进行了更改并添加了代码。但这行不通。另外,我需要根据 itemcontrol 中的项目使其动态化。我将如何实现这一目标?
-
你是指第一次加载时滚动到底部吗?
-
我需要获取宽度,以便我可以使用翻译动画(如新闻收报机)为 Itemcontrol 设置动画,因此我需要获取宽度以设置 To 和 From 属性
标签: c# xaml windows-8 windows-runtime winrt-xaml