Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Xamarin Android Oxyplot刷新不起作用_C#_Xamarin_Xamarin.android_Mvvmcross_Oxyplot - Fatal编程技术网

C# Xamarin Android Oxyplot刷新不起作用

C# Xamarin Android Oxyplot刷新不起作用,c#,xamarin,xamarin.android,mvvmcross,oxyplot,C#,Xamarin,Xamarin.android,Mvvmcross,Oxyplot,我在Xamarin Android中刷新Oxyplot图形时遇到问题。我正在使用Model.InvalidatePlot(true),但仍然不起作用 在我的ViewModel中,我有属性PlotModel和刷新方法,如下面的代码。GroupSales是我的MvxObservableGroupSales集合 public void RefreshTest() { GroupSales.Clear(); var groupSal

我在Xamarin Android中刷新Oxyplot图形时遇到问题。我正在使用Model.InvalidatePlot(true),但仍然不起作用

在我的ViewModel中,我有属性PlotModel和刷新方法,如下面的代码。GroupSales是我的MvxObservableGroupSales集合

    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更改移动方向时,它才会更新(因为Im使用纵向和横向两个视图,所以它会再次初始化),但我需要在单击“刷新”按钮后刷新PlotModel

我已经尝试在Android fragment中调用此方法,并将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);
                }
            };
  var bindset = this.CreateBindingSet<GroupSalesFragment, GroupSalesViewModel>();
            bindset.Bind(plotView).For(c => c.Model).To(vm => vm.Model);
            bindset.Apply();
Button-Button=\u-view.findviewbyd(Resource.Id.refreshButton);
按钮。单击+=委派
{
ViewModel.RefreshTest();
if(plotView!=null&&ViewModel.Model!=null)
{
plotView.InvalidatePlot(真);
plotView.Invalidate();
plotView.RefreshDrawableState();
plotView.Model.InvalidatePlot(真);
}
};
但仍然不起作用。。。。有人能帮我吗

编辑

我在片段中初始化模型,如下所示:

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

哦,我明白了。。。我只是像这样绑定在片段中:

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);
                }
            };
  var bindset = this.CreateBindingSet<GroupSalesFragment, GroupSalesViewModel>();
            bindset.Bind(plotView).For(c => c.Model).To(vm => vm.Model);
            bindset.Apply();
var bindset=this.CreateBindingSet();
bindset.Bind(plotView).For(c=>c.Model).To(vm=>vm.Model);
bindset.Apply();
它现在正在工作