From 954ca442f538c71441b1fbcd68a4769b487813a6 Mon Sep 17 00:00:00 2001 From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:22:40 +0800 Subject: [PATCH] feat: redesign banner demo. --- demo/Ursa.Demo/Pages/BannerDemo.axaml | 103 ++++++++++-------- demo/Ursa.Demo/Pages/BannerDemo.axaml.cs | 15 --- .../ViewModels/BannerDemoViewModel.cs | 39 ++++++- 3 files changed, 92 insertions(+), 65 deletions(-) diff --git a/demo/Ursa.Demo/Pages/BannerDemo.axaml b/demo/Ursa.Demo/Pages/BannerDemo.axaml index d8e6b85..9b6c591 100644 --- a/demo/Ursa.Demo/Pages/BannerDemo.axaml +++ b/demo/Ursa.Demo/Pages/BannerDemo.axaml @@ -4,58 +4,65 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:pages="clr-namespace:Ursa.Demo.Pages" xmlns:u="https://irihi.tech/ursa" - x:DataType="pages:BannerDemoViewModel" + xmlns:vm="clr-namespace:Ursa.Demo.ViewModels" + x:DataType="vm:BannerDemoViewModel" mc:Ignorable="d"> - + - - + + - - - - - - + Header="{Binding Title}" + Content="{Binding Content}" /> + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/demo/Ursa.Demo/Pages/BannerDemo.axaml.cs b/demo/Ursa.Demo/Pages/BannerDemo.axaml.cs index e0d16d1..421a235 100644 --- a/demo/Ursa.Demo/Pages/BannerDemo.axaml.cs +++ b/demo/Ursa.Demo/Pages/BannerDemo.axaml.cs @@ -1,7 +1,4 @@ using Avalonia.Controls; -using Avalonia.Controls.Notifications; -using Avalonia.Markup.Xaml; -using CommunityToolkit.Mvvm.ComponentModel; using Ursa.Demo.ViewModels; namespace Ursa.Demo.Pages; @@ -13,16 +10,4 @@ public partial class BannerDemo : UserControl InitializeComponent(); this.DataContext = new BannerDemoViewModel(); } - - private void InitializeComponent() - { - AvaloniaXamlLoader.Load(this); - } -} - -public partial class BannerDemoViewModel : ViewModelBase -{ - [ObservableProperty] private NotificationType _selectedType; - [ObservableProperty] private bool _bordered; - [ObservableProperty] private bool _canClose; } \ No newline at end of file diff --git a/demo/Ursa.Demo/ViewModels/BannerDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/BannerDemoViewModel.cs index 34a0ded..d3331b1 100644 --- a/demo/Ursa.Demo/ViewModels/BannerDemoViewModel.cs +++ b/demo/Ursa.Demo/ViewModels/BannerDemoViewModel.cs @@ -1,6 +1,41 @@ +using CommunityToolkit.Mvvm.ComponentModel; + namespace Ursa.Demo.ViewModels; -public class BannerDemoViewModel: ViewModelBase +public partial class BannerDemoViewModel : ViewModelBase { - + private string? _oldTitle = string.Empty; + private string? _oldContent = string.Empty; + [ObservableProperty] private string? _title = "Welcome to Ursa"; + [ObservableProperty] private string? _content = "This is the Demo of Ursa Banner."; + [ObservableProperty] private bool _bordered; + + [ObservableProperty] private bool _setTitleNull = true; + [ObservableProperty] private bool _setContentNull = true; + + partial void OnSetTitleNullChanged(bool value) + { + if (value) + { + Title = _oldTitle; + } + else + { + _oldTitle = Title; + Title = null; + } + } + + partial void OnSetContentNullChanged(bool value) + { + if (value) + { + Content = _oldContent; + } + else + { + _oldContent = Content; + Content = null; + } + } } \ No newline at end of file