我正在尝试使用 XAML 创建一个滚动新闻提要,并且在提要被切断时遇到了一些麻烦。现在我只是在我的 XmlDataProvider 中使用了一些假新闻标题,但它们将来自 RSS 提要。
<Window.Resources>
<XmlDataProvider x:Key="NewsFeed" XPath="/rss/Channel/Item">
<x:XData>
<rss xmlns="">
<Channel>
<Item>
<Headline>Cash-Strapped Oklahoma To Conduct Executions By Hammering Squad</Headline>
</Item>
<Item>
<Headline>PetSmart Manager Does Morning Sweep Of Enclosures For Dead Ones Before Opening Doors For Day</Headline>
</Item>
<Item>
<Headline>Lovestruck Arabian Princess Begs Father To Spare John Kerry’s Life</Headline>
</Item>
<Item>
<Headline>Frantic Joe Biden Searching Dog Shelter For Bo Look-Alike</Headline>
</Item>
<Item>
<Headline>Pope Tweets Picture Of Self With God</Headline>
</Item>
<Item>
<Headline>Wes Welker Fielding Offers From Numerous Concussion Researchers</Headline>
</Item>
</Channel>
</rss>
</x:XData>
</XmlDataProvider>
</Window.Resources>
这是带有包含动画文本的 Item 控件的网格。
<Grid Background="Gray">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="45" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Label Content="RSS" FontSize="16" Margin="10,0,0,0" FontStyle="Italic" Foreground="White" />
<ItemsControl Grid.Row="0" Grid.Column="1" Margin="10,0,10,0" Height="35" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Padding="0" DataContext="{Binding Source={StaticResource NewsFeed}, XPath=/rss/Channel/Item}" ItemsSource="{Binding XPath=//Headline}">
<!-- -->
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" Width="Auto" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Center" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<Border BorderBrush="CadetBlue" BorderThickness="2" Height="Auto" Padding="0" HorizontalAlignment="Stretch" VerticalAlignment="Center" ClipToBounds="True">
<StackPanel ClipToBounds="True">
<StackPanel.RenderTransform>
<TranslateTransform x:Name="translate" />
</StackPanel.RenderTransform>
<StackPanel.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard>
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation From="1000" To="-1000" Storyboard.TargetName="translate" Storyboard.TargetProperty="X" Duration="0:0:25" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</StackPanel.Triggers>
<ItemsPresenter />
</StackPanel>
</Border>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Background="CadetBlue" Width="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="Auto" ClipToBounds="True" Margin="3">
<TextBlock VerticalAlignment="Center" Foreground="Black" Text="//" Margin="0,0,8,0" ClipToBounds="True" />
<TextBlock VerticalAlignment="Center" Foreground="LightYellow" Text="{Binding Path=InnerText}" Margin="0,0,8,0" ClipToBounds="True" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Control.Margin" Value="5" />
<Setter Property="Control.VerticalAlignment" Value="Stretch" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
</Grid>
动画正在运行,但正在切断第三个标题。现在它显示了 6 个标题中的 3 个。为什么没有呈现所有的头条新闻?