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 @@ - - + - + + + + + +