I did a sample in C#, below is the code:
XAML code is:
<Window.DataContext>
<local:MyViewModel></local:MyViewModel>
</Window.DataContext>
<StackPanel>
<Polyline Height="300" Name="_myPolyline" Stroke="{Binding myModel.ColorName}" Tag="123213" StrokeThickness="4" Points="{Binding myModel.points}" ></Polyline>
</StackPanel>
The cs code is:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
MyViewModel vm = new MyViewModel();
_myPolyline.Points = vm.myModel.points;
}
}
public class MyViewModel
{
public int currentSecond = 0;
Random rd = new Random();
public PointCollection LtPoint = new PointCollection();
public MyModel myModel { get; set; } = new MyModel();
public MyViewModel()
{
DispatcherTimer timer = new DispatcherTimer();
timer.Tick += Timer_Tick;
timer.Interval = TimeSpan.FromMilliseconds(500);
timer.Start();
myModel = new MyModel()
{
points = LtPoint,
ColorName = "Blue"
};
}
private void Timer_Tick(object sender, EventArgs e)
{
currentSecond++;
double x = currentSecond * 10;
double y = rd.Next(1, 200);
LtPoint.Add(new Point(x, y));
}
}
public class MyModel
{
public PointCollection points { get; set; } = new PointCollection();
public string ColorName { get; set; }
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.