Hi,
you can display PLine and use Interactivity from NuGet. Try following demo:
XAML:
And classes in VB.NET:
Imports System.Threading
Imports System.Windows.Interactivity
Namespace WpfApp052
Public Class ViewModel
Public Sub New()
Dim sc = SynchronizationContext.Current ' UI-Thread context
' asynchonously fill array vlues with data
Task.Run(Sub()
Do
Thread.Sleep(20) ' 50 Hz
' fill array with Y-values
For i = 0 To values.GetUpperBound(0)
values(i) = rnd.Next(1, 300)
Next
' refresh polyline in UI thread
If CanvasView IsNot Nothing Then sc.Post(New SendOrPostCallback(AddressOf ShowValues), Nothing)
Loop
End Sub)
End Sub
Private rnd As New Random()
Public Property CanvasView As Canvas
Private pline As New Polyline()
Private pointCollection As New PointCollection()
Private values(99) As Integer
Public Sub ShowValues(state As Object)
If (CanvasView.Children.Count = 0) Then ' first Then Call, fill polyline And add To Canvas
pline.Stroke = New SolidColorBrush(Color.FromRgb(60, 125, 200))
pline.StrokeThickness = 1
pline.Points = pointCollection
For i = 0 To values.GetUpperBound(0)
pointCollection.Add(New Point(i * 4, values(i)))
Next
CanvasView.Children.Add(pline)
Else
' write New values in polyline
For i = 0 To values.GetUpperBound(0)
Dim pt = pointCollection(i)
pt.Y = values(i)
pointCollection(i) = pt
Next
End If
End Sub
End Class
'''
''' Behavior to get Convas in ViewModel (MVVM)
'''
Public Class CanvasBehavior
Inherits Behavior(Of Canvas)
Protected Overrides Sub OnAttached()
AddHandler AssociatedObject.Loaded, AddressOf AssociatedObject_Loaded
End Sub
Private Sub AssociatedObject_Loaded(sender As Object, e As RoutedEventArgs)
CType(AssociatedObject.DataContext, ViewModel).CanvasView = AssociatedObject
End Sub
End Class
End Namespace