2017-05-31 2 views
2

Ich habe ein Problem mit der Aktualisierung Oxyplot Graph in Xamarin Android. Ich verwende Model.InvalidatePlot (true), funktioniert aber immer noch nicht.Xamarin Android Oxyplot aktualisieren funktioniert nicht

In meinem ViewModel habe ich Eigenschaft PlotModel und Methode für Refresh wie Code unten. GroupSales ist meine MvxObservableCollection von GroupSale.

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); 
      } 
     } 

Nach Aufruf Methode RefreshTest mein MvxObservableCollection aktualisiert und Modell auch, aber noch auf der Suche gleiche im Blick. Nur wenn Im ändern mobile Ausrichtung sein Update (cuz Im zwei Ansichten für Hoch-und Querformat verwendet, so dass es wieder initialisiert), aber ich brauche PlotModel nach dem Klicken auf Aktualisieren aktualisieren.

Ich habe bereits versucht, rufen Sie diese Methode in Android-Fragment und Invalidete PlotView und Modell wie folgt aus:

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); 
       } 
      }; 

aber immer noch nicht funktioniert .... Kann mir jemand helfen?

EDIT

I Modell in Fragment wie folgt initialisieren:

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

Antwort

0

Oh, ich habe es ... ich Fragment wie diese binden nur:

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

Und sein arbeitet jetzt ....

Verwandte Themen