From e9922490004596969503b7e7620fcc4e748d5b8a Mon Sep 17 00:00:00 2001 From: SKProCH Date: Sun, 11 Feb 2024 01:32:06 +0300 Subject: [PATCH] Make demo use compiled bindings --- Material.Demo/Material.Demo.csproj | 2 - Material.Demo/Pages/ExpandersDemo.axaml | 3 +- Material.Demo/Pages/FieldsDemo.axaml | 4 +- Material.Demo/Pages/Home.axaml | 4 +- Material.Demo/Pages/IconsDemo.axaml | 3 +- .../Pages/ProgressIndicatorDemo.axaml | 4 +- .../Pages/ProgressIndicatorDemo.axaml.cs | 60 +------------------ .../ProgressIndicatorDemoViewModel.cs | 52 ++++++++++++++++ 8 files changed, 67 insertions(+), 65 deletions(-) create mode 100644 Material.Demo/ViewModels/ProgressIndicatorDemoViewModel.cs diff --git a/Material.Demo/Material.Demo.csproj b/Material.Demo/Material.Demo.csproj index 0703b617..72bb7baa 100644 --- a/Material.Demo/Material.Demo.csproj +++ b/Material.Demo/Material.Demo.csproj @@ -6,8 +6,6 @@ false 11.0.9 false - - false diff --git a/Material.Demo/Pages/ExpandersDemo.axaml b/Material.Demo/Pages/ExpandersDemo.axaml index 86b10fbc..f72c272e 100644 --- a/Material.Demo/Pages/ExpandersDemo.axaml +++ b/Material.Demo/Pages/ExpandersDemo.axaml @@ -4,7 +4,8 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" xmlns:viewModels="clr-namespace:Material.Demo.ViewModels" - x:Class="Material.Demo.Pages.ExpandersDemo"> + x:Class="Material.Demo.Pages.ExpandersDemo" + x:DataType="viewModels:ExpanderDemoViewModel"> diff --git a/Material.Demo/Pages/FieldsDemo.axaml b/Material.Demo/Pages/FieldsDemo.axaml index eb238f45..7fa54667 100644 --- a/Material.Demo/Pages/FieldsDemo.axaml +++ b/Material.Demo/Pages/FieldsDemo.axaml @@ -8,7 +8,9 @@ xmlns:system="clr-namespace:System;assembly=System.Runtime" xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia" xmlns:controls="clr-namespace:Material.Styles.Controls;assembly=Material.Styles" - x:Class="Material.Demo.Pages.FieldsDemo"> + xmlns:viewModels="clr-namespace:Material.Demo.ViewModels" + x:Class="Material.Demo.Pages.FieldsDemo" + x:DataType="viewModels:TextFieldsViewModel"> Only numerics in this field diff --git a/Material.Demo/Pages/Home.axaml b/Material.Demo/Pages/Home.axaml index e4e5dccf..ffd27602 100644 --- a/Material.Demo/Pages/Home.axaml +++ b/Material.Demo/Pages/Home.axaml @@ -1,6 +1,8 @@  + xmlns:pages="clr-namespace:Material.Demo.Pages" + x:Class="Material.Demo.Pages.Home" + x:DataType="pages:Home"> diff --git a/Material.Demo/Pages/IconsDemo.axaml b/Material.Demo/Pages/IconsDemo.axaml index aeeffa1e..cad26e32 100644 --- a/Material.Demo/Pages/IconsDemo.axaml +++ b/Material.Demo/Pages/IconsDemo.axaml @@ -11,7 +11,8 @@ xmlns:assists="clr-namespace:Material.Styles.Assists;assembly=Material.Styles" xmlns:controls="clr-namespace:Material.Styles.Controls;assembly=Material.Styles" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" - x:Class="Material.Demo.Pages.IconsDemo"> + x:Class="Material.Demo.Pages.IconsDemo" + x:DataType="viewModels:IconsDemoViewModel"> diff --git a/Material.Demo/Pages/ProgressIndicatorDemo.axaml b/Material.Demo/Pages/ProgressIndicatorDemo.axaml index 388c6103..943cd01a 100644 --- a/Material.Demo/Pages/ProgressIndicatorDemo.axaml +++ b/Material.Demo/Pages/ProgressIndicatorDemo.axaml @@ -5,7 +5,9 @@ mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" xmlns:showMeTheXaml="clr-namespace:ShowMeTheXaml;assembly=ShowMeTheXaml.Avalonia" xmlns:controls="clr-namespace:Material.Styles.Controls;assembly=Material.Styles" - x:Class="Material.Demo.Pages.ProgressIndicatorDemo"> + xmlns:viewModels="clr-namespace:Material.Demo.ViewModels" + x:Class="Material.Demo.Pages.ProgressIndicatorDemo" + x:DataType="viewModels:ProgressIndicatorDemoViewModel"> diff --git a/Material.Demo/Pages/ProgressIndicatorDemo.axaml.cs b/Material.Demo/Pages/ProgressIndicatorDemo.axaml.cs index c920000c..1c7bc544 100644 --- a/Material.Demo/Pages/ProgressIndicatorDemo.axaml.cs +++ b/Material.Demo/Pages/ProgressIndicatorDemo.axaml.cs @@ -2,70 +2,14 @@ using System.Timers; using Avalonia; using Avalonia.Controls; +using Material.Demo.ViewModels; namespace Material.Demo.Pages { public partial class ProgressIndicatorDemo : UserControl { - private readonly Context context; - private readonly Timer timer; - private int caseProgress; - public ProgressIndicatorDemo() { InitializeComponent(); - timer = new Timer(1000); - timer.Elapsed += Timer_Elapsed; - - DataContext = context = new Context(); - - AttachedToVisualTree += ProgressIndicatorDemo_AttachedToVisualTree; - } - - private void ProgressIndicatorDemo_AttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e) { - timer.Start(); - } - - private void Timer_Elapsed(object? sender, ElapsedEventArgs e) { - context.Progress = SwitchProgress(); - } - - private double SwitchProgress() { - switch (caseProgress) { - case 0: - caseProgress++; - return 30; - case 1: - caseProgress++; - return 45; - case 2: - caseProgress++; - return 50; - case 3: - caseProgress++; - return 80; - case 4: - caseProgress++; - return 100; - case 5: - caseProgress = 0; - return 0; - default: - caseProgress = 0; - return 0; - } - } - - public class Context : INotifyPropertyChanged { - private double m_Progress; - - public double Progress { - get => m_Progress; - set { - m_Progress = value; - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Progress))); - } - } - - public event PropertyChangedEventHandler? PropertyChanged; + DataContext = new ProgressIndicatorDemoViewModel(); } } } \ No newline at end of file diff --git a/Material.Demo/ViewModels/ProgressIndicatorDemoViewModel.cs b/Material.Demo/ViewModels/ProgressIndicatorDemoViewModel.cs new file mode 100644 index 00000000..c61b9b3d --- /dev/null +++ b/Material.Demo/ViewModels/ProgressIndicatorDemoViewModel.cs @@ -0,0 +1,52 @@ +using System.Timers; + +namespace Material.Demo.ViewModels; + +public class ProgressIndicatorDemoViewModel : ViewModelBase { + private readonly Timer _timer; + private double _progress; + private int _progressSate; + + public ProgressIndicatorDemoViewModel() { + _timer = new Timer(1000); + _timer.Elapsed += Timer_Elapsed; + } + + public double Progress { + get => _progress; + set { + _progress = value; + OnPropertyChanged(); + } + } + + private void Timer_Elapsed(object? sender, ElapsedEventArgs e) { + Progress = SwitchProgress(); + } + + private double SwitchProgress() { + switch (_progressSate) { + case 0: + _progressSate++; + return 30; + case 1: + _progressSate++; + return 45; + case 2: + _progressSate++; + return 50; + case 3: + _progressSate++; + return 80; + case 4: + _progressSate++; + return 100; + case 5: + _progressSate = 0; + return 0; + default: + _progressSate = 0; + return 0; + } + } +} \ No newline at end of file