2009-01-23 56 views
5

所以我有一个WPF XAML获取我的RSS提要的标题,并将它们放在一个ListBox中。如何在WPF XAML中创建加载图形?

但是,加载需要大约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> 

回答

6

我的解决方案是实现我的数据和WPF之间的异步层。这完全分离了WPF在数据方面的任何延迟,并为我提供了很好的事件和属性来触发和绑定。

我在View Model or Presenter Model architecture之上建立了这个。我写了a blog post about the basics和一个关于my approach to asynchronous View Models的较长一段。

这里是微调器的XAML。在DataContext它需要执行加载的视图模型。根据StateLoadingIndicator将自己可见并重新崩溃。

<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> 

[来源版权所有© 2009年dasz.at OG;这项工作是在MIT License的许可。]

+0

你杀了你的博客? – bevacqua 2012-11-10 13:35:10

1

你可以可以创建spinny-loady-啄并将其添加到列表框的AdornerLayer。

1

以下视频来自mix08,并引导您完全按照自己的意愿进行操作。

Part 1

Part 2

(手表陆续如果可能的话,它是在Silverlight,但将指向您在正确的方向。)

乐趣。

0

您可以利用XmlDataProviderIsAsynchronous属性和DataChanged事件(我没有尝试):查看文档。 ;-)