canvas rectangle generate

This commit is contained in:
2023-06-21 13:31:29 +09:00
parent 0ec24ba4e1
commit 2d572bcb1b
9 changed files with 215 additions and 0 deletions

View File

@@ -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
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
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();
}
}
}