2017-05-31 42 views
2

我在Xamarin Android刷新Oxyplot圖時遇到問題。我正在使用Model.InvalidatePlot(true),但仍然無法正常工作。Xamarin Android Oxyplot刷新不起作用

在我的ViewModel中,我有屬性PlotModel和刷新方法如下代碼。 GroupSales是我的GroupSale的MvxObservableCollection。

public void RefreshTest() 
     { 
      GroupSales.Clear(); 
      var groupSales = DemoData.GetGroupSaleList(_shop.Id); 

      groupSales.Add(new GroupSale() 
      { 
       Name = "Test", 
       Sum = 5555, 
       Color = Constants.DefaultColor 
      }); 

      foreach (var item in groupSales) 
      { 
       GroupSales.Add(item); 
      } 

      Model = OxyPlotModelCreator.GetGroupSalesModel(GroupSales); 
      Model.InvalidatePlot(true); 
     } 

private PlotModel _model; 
     public PlotModel Model 
     { 
      get { return _model; } 
      set 
      { 
       _model = value; 
       RaisePropertyChanged(() => Model); 
      } 
     } 

後調用方法RefreshTest我MvxObservableCollection更新和型號太多,但仍在尋找中取景。只有當Im改變移動方向時,它的更新(cuz Im使用兩個視圖來處理縱向和橫向,以便再次初始化),但是我需要在點擊Refresh按鈕後刷新PlotModel。

我想已經調用Android的碎片這種方法和Invalidete PlotView和型號如下:

Button button = _view.FindViewById<Button>(Resource.Id.refreshButton); 
      button.Click += delegate 
      { 
       ViewModel.RefreshTest(); 
       if (plotView != null && ViewModel.Model != null) 
       { 
        plotView.InvalidatePlot(true); 
        plotView.Invalidate(); 
        plotView.RefreshDrawableState(); 
        plotView.Model.InvalidatePlot(true); 
       } 
      }; 

但仍然does not工作....有人能幫助我嗎?

編輯

我初始化模型片段是這樣的:

var plotView = _view.FindViewById<PlotView>(Resource.Id.groupSalesModel); 
      if (plotView != null && ViewModel.Model != null) 
      { 
       plotView.Model = ViewModel.Model; 
      } 

回答

0

哦,我知道了......我只是在結合片段是這樣的:

var bindset = this.CreateBindingSet<GroupSalesFragment, GroupSalesViewModel>(); 
      bindset.Bind(plotView).For(c => c.Model).To(vm => vm.Model); 
      bindset.Apply(); 

而其現在工作....