Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.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
Wpf 在VB.net中不刷新OxyPlot_Wpf_Vb.net_Xaml_Graph_Oxyplot - Fatal编程技术网

Wpf 在VB.net中不刷新OxyPlot

Wpf 在VB.net中不刷新OxyPlot,wpf,vb.net,xaml,graph,oxyplot,Wpf,Vb.net,Xaml,Graph,Oxyplot,当我遇到对数X轴的问题时,我正在使用VisualStudio绘制数据图表。我现在转向OxyPlot,然而,我在获取数据填充方面遇到了巨大的问题。我从windows窗体切换到WPF,因此这可能是绑定的XAML问题(不确定)。基本上,我在VB.net中使用了他们非常有限的示例,并且可以轻松地复制它。我正在努力用OxyPlot复制动态绘图。以下是我目前的代码: 样本:() 然后我尝试添加更多数据来模拟动态加载数据。我也知道我必须使用invalidate()并且Update()已被弃用。我在表单中添加了

当我遇到对数X轴的问题时,我正在使用VisualStudio绘制数据图表。我现在转向OxyPlot,然而,我在获取数据填充方面遇到了巨大的问题。我从windows窗体切换到WPF,因此这可能是绑定的XAML问题(不确定)。基本上,我在VB.net中使用了他们非常有限的示例,并且可以轻松地复制它。我正在努力用OxyPlot复制动态绘图。以下是我目前的代码:

样本:()

然后我尝试添加更多数据来模拟动态加载数据。我也知道我必须使用invalidate()并且Update()已被弃用。我在表单中添加了一个按钮,并给它另一个系列,以便在单击时添加到图表中

按钮点击:

Private Sub test_Click(sender As Object, e As RoutedEventArgs) Handles test.Click


        Dim series3 = New LineSeries()
        series3.Title = "Series 3"
        series3.MarkerType = MarkerType.Square
        series3.Points.Add(New DataPoint(20, 20))
        series3.Points.Add(New DataPoint(21, 21))
        series3.Points.Add(New DataPoint(22, 22))
        series3.Points.Add(New DataPoint(23, 23))
        series3.Points.Add(New DataPoint(24, 24))
        Model.Series.Add(series3)
        Model.InvalidatePlot(True)
    End Sub

这也是他们更新数据图的可爱参考:

在事件处理程序中,在调用
InvalidatePlot
之前,您需要将
系列3
添加到
模型中

Model.Series.Add(series3);
Model.InvalidatePlot(true);
更新

此外,还需要确保PlotModel将更改通知视图(XAML)。如果我使用示例(您指定的示例),我会修改代码如下:

Public Class MainViewModel Implements INotifyPropertyChanged

    Private mmodel As PlotModel

    Public Event PropertyChanged As PropertyChangedEventHandler _
        Implements INotifyPropertyChanged.PropertyChanged

    Public Sub New()

        Model = New PlotModel()

        Model.Title = "Simple example"
        Model.Subtitle = "using OxyPlot in VB.NET"

        Dim series1 = New LineSeries()
        series1.Title="Series 1"
        series1.MarkerType = MarkerType.Circle
        series1.Points.Add(New DataPoint(0, 0))
        series1.Points.Add(New DataPoint(10, 18))
        series1.Points.Add(New DataPoint(20, 12))
        series1.Points.Add(New DataPoint(30, 8))
        series1.Points.Add(New DataPoint(40, 15))

        Dim series2 = New LineSeries()
        series2.Title="Series 2"
        series2.MarkerType = MarkerType.Square
        series2.Points.Add(New DataPoint(0, 4))
        series2.Points.Add(New DataPoint(10, 12))
        series2.Points.Add(New DataPoint(20, 16))
        series2.Points.Add(New DataPoint(30, 25))
        series2.Points.Add(New DataPoint(40, 5))

        Model.Series.Add(series1)
        Model.Series.Add(series2)

    End Sub

    Property Model() As PlotModel
        Get
            Return mmodel
        End Get
        Set(value As PlotModel)
            mmodel = value
            NotifyPropertyChanged("Model")
        End Set
    End Property

    Private Sub test_Click(sender As Object, e As RoutedEventArgs) Handles test.Click

        Dim series3 = New LineSeries()
        series3.Title = "Series 3"
        series3.MarkerType = MarkerType.Square
        series3.Points.Add(New DataPoint(20, 20))
        series3.Points.Add(New DataPoint(21, 21))
        series3.Points.Add(New DataPoint(22, 22))
        series3.Points.Add(New DataPoint(23, 23))
        series3.Points.Add(New DataPoint(24, 24))
        Model.Series.Add(series3)
        Model.InvalidatePlot(True)
    End Sub

End Class

我的错误是遗漏了这一点,但是即使你更新了代码,它仍然不会触发绘图更新。嗯,好的。。。那么,正如您在问题的开头所提到的,可能是XAML中的数据绑定问题。。。您的
test\u Click
函数需要通知您的视图(XAML),即
PlotModel
已使用
PropertyChangedEventHandler
进行了更改。在XAML中,当绑定到PlotModel时,指定:
UpdateSourceTrigger=PropertyChanged
-我将更新我的答案Harveyaj,我感谢您的帮助,但是,实际上我在XAML中最为挣扎(因为我是新手)。您认为您可以为我发布一个XAML示例,以便更好地引用您的上述评论吗?@AustinEfnor我在GitHub上创建了一个小项目:我使用VS2017,但这也适用于早期版本。
Public Class MainViewModel Implements INotifyPropertyChanged

    Private mmodel As PlotModel

    Public Event PropertyChanged As PropertyChangedEventHandler _
        Implements INotifyPropertyChanged.PropertyChanged

    Public Sub New()

        Model = New PlotModel()

        Model.Title = "Simple example"
        Model.Subtitle = "using OxyPlot in VB.NET"

        Dim series1 = New LineSeries()
        series1.Title="Series 1"
        series1.MarkerType = MarkerType.Circle
        series1.Points.Add(New DataPoint(0, 0))
        series1.Points.Add(New DataPoint(10, 18))
        series1.Points.Add(New DataPoint(20, 12))
        series1.Points.Add(New DataPoint(30, 8))
        series1.Points.Add(New DataPoint(40, 15))

        Dim series2 = New LineSeries()
        series2.Title="Series 2"
        series2.MarkerType = MarkerType.Square
        series2.Points.Add(New DataPoint(0, 4))
        series2.Points.Add(New DataPoint(10, 12))
        series2.Points.Add(New DataPoint(20, 16))
        series2.Points.Add(New DataPoint(30, 25))
        series2.Points.Add(New DataPoint(40, 5))

        Model.Series.Add(series1)
        Model.Series.Add(series2)

    End Sub

    Property Model() As PlotModel
        Get
            Return mmodel
        End Get
        Set(value As PlotModel)
            mmodel = value
            NotifyPropertyChanged("Model")
        End Set
    End Property

    Private Sub test_Click(sender As Object, e As RoutedEventArgs) Handles test.Click

        Dim series3 = New LineSeries()
        series3.Title = "Series 3"
        series3.MarkerType = MarkerType.Square
        series3.Points.Add(New DataPoint(20, 20))
        series3.Points.Add(New DataPoint(21, 21))
        series3.Points.Add(New DataPoint(22, 22))
        series3.Points.Add(New DataPoint(23, 23))
        series3.Points.Add(New DataPoint(24, 24))
        Model.Series.Add(series3)
        Model.InvalidatePlot(True)
    End Sub

End Class