|
@@ -0,0 +1,103 @@
|
|
|
+using Avalonia.Controls;
|
|
|
+using Avalonia.Controls.Shapes;
|
|
|
+using Avalonia.Media;
|
|
|
+using Avalonia.Threading;
|
|
|
+using AvaloniaMVVM.Models;
|
|
|
+using ReactiveUI;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+
|
|
|
+namespace AvaloniaMVVM.ViewModels
|
|
|
+{
|
|
|
+
|
|
|
+ public class MainWindowViewModel : ViewModelBase
|
|
|
+ {
|
|
|
+ DispatcherTimer timer = new DispatcherTimer();
|
|
|
+ public MainWindowViewModel()
|
|
|
+ {
|
|
|
+
|
|
|
+ timer.Interval = new TimeSpan(0, 0, 5);
|
|
|
+ timer.Tick += new EventHandler(timer_tick);
|
|
|
+ }
|
|
|
+ #region
|
|
|
+ public int Count
|
|
|
+ {
|
|
|
+ get => ModelClass.count;
|
|
|
+ set => this.RaiseAndSetIfChanged(ref ModelClass.count, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<string> SurnameList => ModelClass.surnameList;
|
|
|
+
|
|
|
+ public string SelectedSurname => ModelClass.surnameList[0];
|
|
|
+
|
|
|
+ public void AddCount()
|
|
|
+ {
|
|
|
+ Count++;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ Canvas _can;
|
|
|
+
|
|
|
+ public Canvas Can
|
|
|
+ {
|
|
|
+ get => _can;
|
|
|
+ set => this.RaiseAndSetIfChanged(ref _can, value);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void timer_tick(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ CreateCaptha();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void CreateCaptha()
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ Random rnd = new Random();
|
|
|
+ SolidColorBrush color = new SolidColorBrush(Color.FromRgb(Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(255)), Convert.ToByte(rnd.Next(255))));
|
|
|
+
|
|
|
+
|
|
|
+ Canvas canvas = new Canvas()
|
|
|
+ {
|
|
|
+ Width = 400,
|
|
|
+ Height = 400,
|
|
|
+ Background = color
|
|
|
+ };
|
|
|
+
|
|
|
+ for (int i=0; i<3; i++)
|
|
|
+ {
|
|
|
+ TextBlock number = new TextBlock()
|
|
|
+ {
|
|
|
+ Text = rnd.Next(10).ToString(),
|
|
|
+ FontSize = 150,
|
|
|
+ Foreground = Brushes.Black,
|
|
|
+ Padding = new Avalonia.Thickness(rnd.Next(100), rnd.Next(50))
|
|
|
+ };
|
|
|
+
|
|
|
+ canvas.Children.Add(number);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (int i=0; i<20; i++) {
|
|
|
+ Line line = new Line()
|
|
|
+ {
|
|
|
+ StartPoint = new Avalonia.Point(rnd.Next(400), rnd.Next(400)),
|
|
|
+ EndPoint = new Avalonia.Point(rnd.Next(400), rnd.Next(400)),
|
|
|
+ Stroke = Brushes.White,
|
|
|
+ StrokeThickness = 3
|
|
|
+ };
|
|
|
+
|
|
|
+ canvas.Children.Add(line);
|
|
|
+ }
|
|
|
+ timer.Start();
|
|
|
+ Can = canvas;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|