2016-11-15 4 views
0

私はReactiveUIの新機能を使用していますので、そこでは専門家の助けが必要です。ReactiveUIとリストの変更に応答する

私はUWPアプリケーションをC#に、アイテムの束を示すListViewを含むページを持っています(どのようなタイプのアイテムでも関係ないので、整数の束を示しているとします)。

Page.Loadedが呼び出されると、サーバーにクエリを送信し、結果(整数の配列)を取得し、ListViewに結果を設定します。

私がしたいのは、サーバーからデータが受信されるまで、プログレスリングを表示することです。リストがポピュレートされます(つまり、新しいアイテムがすべて追加されます)。これらの2つのアクションが完了したら、ProgressRingを非表示にしたいと思います。

ReactiveUIを使用して上記を実行したいと思いますが、これを行う方法を理解できませんでした。

すべてのヘルプは

答えて

0

をいただければ幸い私はUWPで働いたことはないが、私は役に立つことを願っWPF、との例を提供することができます。 は、この例では、私はMahApps.Metro

のViewModel

public class MainViewModel : ReactiveObject 
{ 
    private readonly ObservableAsPropertyHelper<bool> _isLoading; 

    public MainViewModel() 
    { 
     Load = ReactiveCommand.CreateFromTask(async() => 
     { 
      // Simulating a long running task, like DB query 
      await Task.Delay(TimeSpan.FromSeconds(10)); 
      // Populating list 
      Items.Clear(); 
      Items.AddRange(Enumerable.Range(0, 30).Where(x => x%2 == 0)); 
     }); 
     Load.IsExecuting.ToProperty(this, x => x.IsLoading, out _isLoading); 
    } 

    public bool IsLoading => _isLoading.Value; 
    public ReactiveList<int> Items { get; } = new ReactiveList<int>(); 
    public ReactiveCommand<Unit, Unit> Load { get; } 
} 

ビュー

public partial class MainWindow : IViewFor<MainViewModel> 
{ 
    public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(nameof(ViewModel), typeof(MainViewModel), typeof(MainWindow)); 
    public MainWindow() 
    { 
     InitializeComponent(); 
     ViewModel = new MainViewModel(); 
     this.OneWayBind(ViewModel, x => x.Items, x => x.ListView.ItemsSource); 
     this.OneWayBind(ViewModel, x => x.IsLoading, x => x.ProgressRing.IsActive); 
     this.Events().Loaded.Subscribe(_ => this.ViewModel.Load.Execute().Subscribe()); 
    } 
    public MainViewModel ViewModel 
    { 
     get { return (MainViewModel)GetValue(ViewModelProperty); } 
     set { SetValue(ViewModelProperty, value); } 
    } 

    object IViewFor.ViewModel 
    { 
     get { return ViewModel; } 
     set { ViewModel = (MainViewModel)value; } 
    } 
} 
<Window x:Class="ProgressRing.MainWindow" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls" 
        Title="MainWindow"> 
<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition /> 
     <RowDefinition Height="Auto" /> 
    </Grid.RowDefinitions> 
    <ScrollViewer Grid.Row="0"> 
     <ListView x:Name="ListView" ItemStringFormat="Item {0}" /> 
    </ScrollViewer> 
    <controls:ProgressRing x:Name="ProgressRing" Grid.Row="1" /> 
</Grid> 

から進捗リングを使用しました
関連する問題