From 2d572bcb1bf4998edb33dfae2cd2c1e5646decda Mon Sep 17 00:00:00 2001 From: syneffort Date: Wed, 21 Jun 2023 13:31:29 +0900 Subject: [PATCH] canvas rectangle generate --- PacticeSolution/MVVMCanvasRectangle/App.xaml | 9 +++ .../MVVMCanvasRectangle/App.xaml.cs | 17 +++++ .../MVVMCanvasRectangle/AssemblyInfo.cs | 10 +++ .../MVVMCanvasRectangle.csproj | 10 +++ .../MVVMCanvasRectangle/MainWindow.xaml | 35 ++++++++++ .../MVVMCanvasRectangle/MainWindow.xaml.cs | 64 +++++++++++++++++++ .../MVVMCanvasRectangle/Model/RectItem.cs | 16 +++++ .../ViewModel/RectModelView.cs | 48 ++++++++++++++ PacticeSolution/PacticeSolution.sln | 6 ++ 9 files changed, 215 insertions(+) create mode 100644 PacticeSolution/MVVMCanvasRectangle/App.xaml create mode 100644 PacticeSolution/MVVMCanvasRectangle/App.xaml.cs create mode 100644 PacticeSolution/MVVMCanvasRectangle/AssemblyInfo.cs create mode 100644 PacticeSolution/MVVMCanvasRectangle/MVVMCanvasRectangle.csproj create mode 100644 PacticeSolution/MVVMCanvasRectangle/MainWindow.xaml create mode 100644 PacticeSolution/MVVMCanvasRectangle/MainWindow.xaml.cs create mode 100644 PacticeSolution/MVVMCanvasRectangle/Model/RectItem.cs create mode 100644 PacticeSolution/MVVMCanvasRectangle/ViewModel/RectModelView.cs diff --git a/PacticeSolution/MVVMCanvasRectangle/App.xaml b/PacticeSolution/MVVMCanvasRectangle/App.xaml new file mode 100644 index 0000000..689121f --- /dev/null +++ b/PacticeSolution/MVVMCanvasRectangle/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/PacticeSolution/MVVMCanvasRectangle/App.xaml.cs b/PacticeSolution/MVVMCanvasRectangle/App.xaml.cs new file mode 100644 index 0000000..01a35bb --- /dev/null +++ b/PacticeSolution/MVVMCanvasRectangle/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace MVVMCanvasRectangle +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/PacticeSolution/MVVMCanvasRectangle/AssemblyInfo.cs b/PacticeSolution/MVVMCanvasRectangle/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/PacticeSolution/MVVMCanvasRectangle/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/PacticeSolution/MVVMCanvasRectangle/MVVMCanvasRectangle.csproj b/PacticeSolution/MVVMCanvasRectangle/MVVMCanvasRectangle.csproj new file mode 100644 index 0000000..4106cb0 --- /dev/null +++ b/PacticeSolution/MVVMCanvasRectangle/MVVMCanvasRectangle.csproj @@ -0,0 +1,10 @@ + + + + WinExe + net6.0-windows + enable + true + + + diff --git a/PacticeSolution/MVVMCanvasRectangle/MainWindow.xaml b/PacticeSolution/MVVMCanvasRectangle/MainWindow.xaml new file mode 100644 index 0000000..87bf29b --- /dev/null +++ b/PacticeSolution/MVVMCanvasRectangle/MainWindow.xaml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PacticeSolution/MVVMCanvasRectangle/MainWindow.xaml.cs b/PacticeSolution/MVVMCanvasRectangle/MainWindow.xaml.cs new file mode 100644 index 0000000..7ed4111 --- /dev/null +++ b/PacticeSolution/MVVMCanvasRectangle/MainWindow.xaml.cs @@ -0,0 +1,64 @@ +using MVVMCanvasRectangle.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Timers; +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; +using System.Windows.Threading; + +namespace MVVMCanvasRectangle +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + private System.Timers.Timer _timer; + + public MainWindow() + { + InitializeComponent(); + + _timer = new System.Timers.Timer(); + _timer.Interval = 1000; + _timer.Elapsed -= _timer_Elapsed; + _timer.Elapsed += _timer_Elapsed; + _timer.Start(); + } + + private void _timer_Elapsed(object? sender, ElapsedEventArgs e) + { + if (this.Dispatcher.Thread != Thread.CurrentThread) + { + this.Dispatcher.Invoke(DispatcherPriority.Normal, () => + { + AddOneRect(); + }); + } + else + { + AddOneRect(); + } + } + + private void AddOneRect() + { + RectModelView dataContext = this.DataContext as RectModelView; + if (dataContext == null) + return; + + dataContext.AddOne(); + } + } +} diff --git a/PacticeSolution/MVVMCanvasRectangle/Model/RectItem.cs b/PacticeSolution/MVVMCanvasRectangle/Model/RectItem.cs new file mode 100644 index 0000000..5515ff0 --- /dev/null +++ b/PacticeSolution/MVVMCanvasRectangle/Model/RectItem.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MVVMCanvasRectangle.Model +{ + internal class RectItem + { + public double X { get; set; } + public double Y { get; set; } + public double Width { get; set; } + public double Height { get; set; } + } +} diff --git a/PacticeSolution/MVVMCanvasRectangle/ViewModel/RectModelView.cs b/PacticeSolution/MVVMCanvasRectangle/ViewModel/RectModelView.cs new file mode 100644 index 0000000..63aade6 --- /dev/null +++ b/PacticeSolution/MVVMCanvasRectangle/ViewModel/RectModelView.cs @@ -0,0 +1,48 @@ +using MVVMCanvasRectangle.Model; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MVVMCanvasRectangle.ViewModel +{ + internal class RectModelView : INotifyPropertyChanged + { + private int _count; + public ObservableCollection RectItems { get; set; } + + public event PropertyChangedEventHandler? PropertyChanged; + + public int Count + { + get { return _count; } + set + { + _count = value; + this.RectItems.Clear(); + for (int i = 0; i < _count; i++) + { + this.RectItems.Add(new RectItem { X = i * 40, Y = 10, Width = 30, Height = 30 }); + } + } + } + + public RectModelView() + { + _count = 0; + this.RectItems = new ObservableCollection(); + } + + public void AddOne() + { + RectItem lastRect = this.RectItems.LastOrDefault(); + if (lastRect == null) + this.RectItems.Add(new RectItem() { X = 0, Y = 10, Width = 30, Height = 30 }); + else + this.RectItems.Add(new RectItem() { X = lastRect.X + 40, Y = 10, Width = 30, Height = 30 }); + } + } +} diff --git a/PacticeSolution/PacticeSolution.sln b/PacticeSolution/PacticeSolution.sln index 9a164e9..6dec7ca 100644 --- a/PacticeSolution/PacticeSolution.sln +++ b/PacticeSolution/PacticeSolution.sln @@ -19,6 +19,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVMDatabaseSample", "MVVMD EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MVVMTextInputDetection", "MVVMTextInputDetection\MVVMTextInputDetection.csproj", "{C55A5081-B142-4120-8F62-3991276EF5C2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MVVMCanvasRectangle", "MVVMCanvasRectangle\MVVMCanvasRectangle.csproj", "{C7A96511-E6B9-4F80-9C7B-3ABF4FC0AA4B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -57,6 +59,10 @@ Global {C55A5081-B142-4120-8F62-3991276EF5C2}.Debug|Any CPU.Build.0 = Debug|Any CPU {C55A5081-B142-4120-8F62-3991276EF5C2}.Release|Any CPU.ActiveCfg = Release|Any CPU {C55A5081-B142-4120-8F62-3991276EF5C2}.Release|Any CPU.Build.0 = Release|Any CPU + {C7A96511-E6B9-4F80-9C7B-3ABF4FC0AA4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C7A96511-E6B9-4F80-9C7B-3ABF4FC0AA4B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C7A96511-E6B9-4F80-9C7B-3ABF4FC0AA4B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C7A96511-E6B9-4F80-9C7B-3ABF4FC0AA4B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE