main
syneffort 11 months ago
parent a221d34fb5
commit 257a21321e
  1. 2
      OxyPlotExample/GettingStarted/MainWindow.xaml
  2. 3
      OxyPlotExample/GettingStarted/ViewModels/MainViewModel.cs
  3. 15
      OxyPlotExample/GettingStarted/ViewModels/MainViewModel2.cs
  4. 67
      OxyPlotExample/GettingStarted/ViewModels/MainViewModel3.cs
  5. 26
      OxyPlotExample/GettingStarted/Views/MainViewControl3.xaml
  6. 28
      OxyPlotExample/GettingStarted/Views/MainViewControl3.xaml.cs

@ -13,9 +13,11 @@
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<views:MainViewControl Grid.Row="0"/>
<views:MainViewControl2 Grid.Row="1"/>
<views:MainViewControl3 Grid.Row="2"/>
</Grid>
</Window>

@ -1,4 +1,5 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using OxyPlot;
using OxyPlot.Series;
using System;
@ -6,6 +7,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
namespace GettingStarted.ViewModels
{

@ -1,10 +1,12 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using OxyPlot;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
namespace GettingStarted.ViewModels
{
@ -22,12 +24,11 @@ namespace GettingStarted.ViewModels
Points = new List<DataPoint>()
{
new DataPoint(0, 4),
new DataPoint(10, 13),
new DataPoint(20, 15),
new DataPoint(30, 16),
new DataPoint(40, 12),
new DataPoint(50, 12)
new DataPoint(1, 13),
new DataPoint(2, 15),
new DataPoint(3, 16),
new DataPoint(4, 12),
new DataPoint(5, 12)
};
}
}

@ -0,0 +1,67 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using OxyPlot.Series;
using OxyPlot;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
namespace GettingStarted.ViewModels
{
internal partial class MainViewModel3 : ObservableObject
{
[ObservableProperty]
private PlotModel _myModel;
[ObservableProperty]
private LineSeries _lineSeries;
public MainViewModel3()
{
MyModel = new PlotModel() { Title = "Getting Started with RT Plot" };
LineSeries = new LineSeries() { Title = "Dynamic Data" };
MyModel.Series.Add(LineSeries);
_timer = new System.Timers.Timer();
_timer.Interval = 50;
_timer.Elapsed -= _timer_Elapsed;
_timer.Elapsed += _timer_Elapsed;
}
private int _lastX = 0;
private void _timer_Elapsed(object? sender, ElapsedEventArgs e)
{
Application.Current.Dispatcher.Invoke(() =>
{
LineSeries.Points.Add(new DataPoint(_lastX, Math.Sin(_lastX * 0.1)));
MyModel.InvalidatePlot(true);
_lastX++;
});
}
private bool _isTimerStarted = false;
private System.Timers.Timer _timer;
[RelayCommand]
private void FlipTimer()
{
if (!_isTimerStarted)
{
_timer.Start();
_isTimerStarted = true;
}
else
{
_timer.Stop();
_isTimerStarted = false;
}
}
}
}

@ -0,0 +1,26 @@
<UserControl x:Class="GettingStarted.Views.MainViewControl3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:GettingStarted.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:oxy="http://oxyplot.org/wpf"
xmlns:viewModels="clr-namespace:GettingStarted.ViewModels"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<UserControl.DataContext>
<viewModels:MainViewModel3 />
</UserControl.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<oxy:PlotView Model="{Binding MyModel}" />
<Button Grid.Row="1"
Command="{Binding FlipTimerCommand}"
Content="Start/Stop" />
</Grid>
</UserControl>

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace GettingStarted.Views
{
/// <summary>
/// MainViewControl3.xaml에 대한 상호 작용 논리
/// </summary>
public partial class MainViewControl3 : UserControl
{
public MainViewControl3()
{
InitializeComponent();
}
}
}
Loading…
Cancel
Save