5

所以我有一个小的 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>
4

4 回答 4

6

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

我在View Model 或 Presenter Model 架构之上构建了它。我写了一篇关于基础知识的博文和一篇关于我的异步视图模型方法的长篇文章。

这是微调器的 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;这项工作是在麻省理工学院许可下获得许可的。]

于 2009-02-13T12:58:37.383 回答
1

您可以创建 spinny-loady-thingy 并将其添加到 ListBox 的 AdornerLayer。

于 2009-01-23T16:38:16.577 回答
1

以下视频来自 mix08,并引导您完成您想要的操作。

第1部分

第2部分

(如果可能,请连续观看。它在银光下,但会为您指明正确的方向。)

玩得开心。

于 2009-01-23T16:42:26.567 回答
0

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

于 2009-01-23T17:47:39.320 回答