我使用Itemcontrol創建Windows 8應用程序並綁定數據列表以顯示新聞。我需要創建動畫,如鏈接中顯示的HTML中的新聞動態:http://coolcarousels.frebsite.nl/c/9/ 我將如何實現這一目標?Windows 8獲得ItemControl後的ItemControl寬度
代碼:
<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中的字幕的動畫?
你需要使用一些動畫代碼,無論是在XAML中,或在C#。你能否編輯這個問題來包含你所嘗試的?如果您使用WinJs + HTML,克隆起來會更容易。 :) – WiredPrairie
我已經做了更改並添加了代碼。但那不起作用。另外我需要使它成爲itemcontrol中item的動態。我將如何實現這一目標? –
您是否指第一次加載時滾動到底部? –