2017-05-31 40 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(); 

而其现在工作....