canvas rectangle generate
This commit is contained in:
64
PacticeSolution/MVVMCanvasRectangle/MainWindow.xaml.cs
Normal file
64
PacticeSolution/MVVMCanvasRectangle/MainWindow.xaml.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user