From e8f942b0f64bcc411c2f8845eddf6b7f6b8b3e0f Mon Sep 17 00:00:00 2001 From: lincube Date: Fri, 27 Feb 2026 13:43:27 +0800 Subject: [PATCH] 0.1.2 --- LanMontainDesktop/App.axaml | 5 +- LanMontainDesktop/LanMontainDesktop.csproj | 1 + .../ViewModels/MainWindowViewModel.cs | 2 +- .../Views/Components/ClockWidget.axaml | 23 ++++ .../Views/Components/ClockWidget.axaml.cs | 47 +++++++ LanMontainDesktop/Views/MainWindow.axaml | 81 +++++++++++- LanMontainDesktop/Views/MainWindow.axaml.cs | 116 +++++++++++++++++- 7 files changed, 266 insertions(+), 9 deletions(-) create mode 100644 LanMontainDesktop/Views/Components/ClockWidget.axaml create mode 100644 LanMontainDesktop/Views/Components/ClockWidget.axaml.cs diff --git a/LanMontainDesktop/App.axaml b/LanMontainDesktop/App.axaml index fccc171..d416fcd 100644 --- a/LanMontainDesktop/App.axaml +++ b/LanMontainDesktop/App.axaml @@ -1,5 +1,6 @@ @@ -10,6 +11,6 @@ - + - \ No newline at end of file + diff --git a/LanMontainDesktop/LanMontainDesktop.csproj b/LanMontainDesktop/LanMontainDesktop.csproj index 8106412..979e699 100644 --- a/LanMontainDesktop/LanMontainDesktop.csproj +++ b/LanMontainDesktop/LanMontainDesktop.csproj @@ -24,5 +24,6 @@ All + diff --git a/LanMontainDesktop/ViewModels/MainWindowViewModel.cs b/LanMontainDesktop/ViewModels/MainWindowViewModel.cs index 631ef00..0a6f98d 100644 --- a/LanMontainDesktop/ViewModels/MainWindowViewModel.cs +++ b/LanMontainDesktop/ViewModels/MainWindowViewModel.cs @@ -2,5 +2,5 @@ public partial class MainWindowViewModel : ViewModelBase { - public string Greeting { get; } = "Welcome to Avalonia!"; + public string Greeting { get; } = "A modern desktop shell powered by FluentAvalonia."; } diff --git a/LanMontainDesktop/Views/Components/ClockWidget.axaml b/LanMontainDesktop/Views/Components/ClockWidget.axaml new file mode 100644 index 0000000..3da6dac --- /dev/null +++ b/LanMontainDesktop/Views/Components/ClockWidget.axaml @@ -0,0 +1,23 @@ + + + + + + + diff --git a/LanMontainDesktop/Views/Components/ClockWidget.axaml.cs b/LanMontainDesktop/Views/Components/ClockWidget.axaml.cs new file mode 100644 index 0000000..1f8c555 --- /dev/null +++ b/LanMontainDesktop/Views/Components/ClockWidget.axaml.cs @@ -0,0 +1,47 @@ +using System; +using System.Globalization; +using Avalonia; +using Avalonia.Controls; +using Avalonia.Threading; + +namespace LanMontainDesktop.Views.Components; + +public partial class ClockWidget : UserControl +{ + private readonly DispatcherTimer _timer = new() + { + Interval = TimeSpan.FromSeconds(1) + }; + + public ClockWidget() + { + InitializeComponent(); + + _timer.Tick += OnTimerTick; + AttachedToVisualTree += OnAttachedToVisualTree; + DetachedFromVisualTree += OnDetachedFromVisualTree; + UpdateClock(); + } + + private void OnAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e) + { + UpdateClock(); + _timer.Start(); + } + + private void OnDetachedFromVisualTree(object? sender, VisualTreeAttachmentEventArgs e) + { + _timer.Stop(); + } + + private void OnTimerTick(object? sender, EventArgs e) + { + UpdateClock(); + } + + private void UpdateClock() + { + var now = DateTime.Now; + TimeTextBlock.Text = now.ToString("HH:mm:ss", CultureInfo.CurrentCulture); + } +} diff --git a/LanMontainDesktop/Views/MainWindow.axaml b/LanMontainDesktop/Views/MainWindow.axaml index 84e5fa7..9fa1e71 100644 --- a/LanMontainDesktop/Views/MainWindow.axaml +++ b/LanMontainDesktop/Views/MainWindow.axaml @@ -1,20 +1,91 @@ - - + - + + + + + +