所以我有一个小的WPF XAML,它获取我的RSS提要的标题,并将它们放在ListBox中.
但是,加载大约需要2秒钟.
我怎么能在ListBox中放置某种AJAXy旋转图形,直到数据存在?
这是代码:
<Window x:Class="WpfApplication5.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<StackPanel>
<StackPanel.Resources>
<XmlDataProvider x:Key="ExternalColors" Source="http://www.tanguay.info/web/rss" XPath="/"/>
</StackPanel.Resources>
<TextBlock Text="RSS Feeds:"/>
<ListBox Name="lbColor" Height="200" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Source={StaticResource ExternalColors}, XPath=//item/title}"/>
<TextBlock Text="You selected this feed:"/>
<TextBox
Text="{Binding ElementName=lbColor, Path=SelectedValue}"
Background="{Binding ElementName=lbColor, Path=SelectedValue}">
</TextBox>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
我的解决方案是在我的数据和WPF之间实现异步层.这完全解除了WPF与数据端的任何延迟,并为我提供了很好的事件和属性来触发和绑定.
我在View Model或Presenter Model架构之上构建了它.我写了一篇关于基础知识的博客文章,以及关于异步View模型方法的更长篇幅.
这是微调器的XAML.在DataContext它需要进行加载的View Model.根据它State,它LoadingIndicator将使自己可见并再次崩溃.
<UserControl x:Class="App.WPF.CustomControls.LoadingIndicator"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="20"
Width="20">
<UserControl.Style>
<Style TargetType="{x:Type UserControl}">
<Style.Triggers>
<DataTrigger Binding="{Binding State}"
Value="Active">
<Setter Property="Visibility"
Value="Collapsed" />
</DataTrigger>
<DataTrigger Binding="{Binding State}"
Value="Loading">
<Setter Property="Visibility"
Value="Visible" />
</DataTrigger>
<DataTrigger Binding="{Binding State}"
Value="Invalid">
<Setter Property="Background"
Value="Red" />
<Setter Property="Visibility"
Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Style>
<UserControl.Triggers>
<EventTrigger RoutedEvent="UserControl.Loaded">
<BeginStoryboard>
<Storyboard TargetName="Rotator"
TargetProperty="Angle">
<DoubleAnimation By="360"
Duration="0:0:2"
RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</UserControl.Triggers>
<Rectangle Stroke="Aqua"
StrokeThickness="2"
Width="10"
Height="10">
<Rectangle.RenderTransform>
<RotateTransform x:Name="Rotator"
Angle="0"
CenterX="5"
CenterY="5" />
</Rectangle.RenderTransform>
</Rectangle>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
[来源Copyright©2009 dasz.at OG ; 这项工作是根据麻省理工学院许可证授予的.]