diff --git a/LC_Tutorial/Tutorial/AdvancedPlots/SolidColorWindow.xaml b/LC_Tutorial/Tutorial/AdvancedPlots/SolidColorWindow.xaml new file mode 100644 index 0000000..e2262dc --- /dev/null +++ b/LC_Tutorial/Tutorial/AdvancedPlots/SolidColorWindow.xaml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + Time Energy + + + + + + + + + + + + + + + + + + + + Peak Time Today + 7:08 am + Peak Value Today + 525 kWh + Day Average + 354 kWh + + + + diff --git a/LC_Tutorial/Tutorial/AdvancedPlots/SolidColorWindow.xaml.cs b/LC_Tutorial/Tutorial/AdvancedPlots/SolidColorWindow.xaml.cs new file mode 100644 index 0000000..16748c5 --- /dev/null +++ b/LC_Tutorial/Tutorial/AdvancedPlots/SolidColorWindow.xaml.cs @@ -0,0 +1,85 @@ +using LiveCharts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading; +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.Shapes; + +namespace Tutorial.AdvancedPlots +{ + /// + /// SolidColorWindow.xaml에 대한 상호 작용 논리 + /// + public partial class SolidColorWindow : Window, INotifyPropertyChanged + { + private DateTime _nowDate; + public ChartValues Values { get; set; } + + + public DateTime NowDate + { + get { return _nowDate; } + set + { + _nowDate = value; + OnPropertyChanged(nameof(NowDate)); + } + } + + public SolidColorWindow() + { + InitializeComponent(); + InitInstance(); + } + + public event PropertyChangedEventHandler? PropertyChanged; + + protected virtual void InitInstance() + { + Values = new ChartValues { 150, 375, 420, 500, 160, 140 }; + NowDate = DateTime.Now; + + Random rand = new Random(); + Task.Run(() => + { + while (true) + { + Thread.Sleep(1000); + + Application.Current.Dispatcher.BeginInvoke(() => + { + NowDate = DateTime.Now; + + for (int i = 0; i < Values.Count; i++) + { + Values[i] = rand.Next(100, 500); + } + }); + } + }); + + DataContext = this; + } + + private void OnPropertyChanged(string propertyName) + { + if (PropertyChanged != null) + PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + private void btnUpdate_Click(object sender, RoutedEventArgs e) + { + Chart.Update(true); + } + } +} diff --git a/LC_Tutorial/Tutorial/MainWindow.xaml b/LC_Tutorial/Tutorial/MainWindow.xaml index 30f6357..24b679c 100644 --- a/LC_Tutorial/Tutorial/MainWindow.xaml +++ b/LC_Tutorial/Tutorial/MainWindow.xaml @@ -38,6 +38,7 @@