feat: add auto tick sample.
This commit is contained in:
@@ -5,10 +5,14 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
xmlns:vm="clr-namespace:Ursa.Demo.ViewModels"
|
||||
x:DataType="vm:ClockDemoViewModel"
|
||||
x:CompileBindings="True"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<u:Clock HorizontalAlignment="Left"></u:Clock>
|
||||
<u:Clock HorizontalAlignment="Left" Time="{Binding Time}"></u:Clock>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,6 +1,31 @@
|
||||
namespace Ursa.Demo.ViewModels;
|
||||
using System;
|
||||
using System.Timers;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
public class ClockDemoViewModel
|
||||
namespace Ursa.Demo.ViewModels;
|
||||
|
||||
public partial class ClockDemoViewModel: ObservableObject, IDisposable
|
||||
{
|
||||
private Timer _timer;
|
||||
|
||||
[ObservableProperty] private DateTime _time;
|
||||
public ClockDemoViewModel()
|
||||
{
|
||||
Time = DateTime.Now;
|
||||
_timer = new Timer(1000);
|
||||
_timer.Elapsed += TimerOnElapsed;
|
||||
_timer.Start();
|
||||
}
|
||||
|
||||
private void TimerOnElapsed(object? sender, ElapsedEventArgs e)
|
||||
{
|
||||
Time = DateTime.Now;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_timer.Stop();
|
||||
_timer.Elapsed -= TimerOnElapsed;
|
||||
_timer.Dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user