You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.1 KiB

using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Media.Imaging;
using Avalonia.Threading;
using System;
namespace Bodk.Ava.UI.Views;
public partial class MainWindow : Window
{
private DispatcherTimer _hideMouseTimer;
public MainWindow()
{
InitializeComponent();
this.Loaded += MainWindow_Loaded;
// 初始化定时器,设定2秒后隐藏鼠标
_hideMouseTimer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(2)
};
_hideMouseTimer.Tick += (sender, e) => HideMouse();
// 订阅鼠标移动事件
this.PointerMoved += OnPointerMoved;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
this.Cursor = new Cursor(StandardCursorType.None);
}
private void OnPointerMoved(object sender, PointerEventArgs e)
{
this.Cursor = new Cursor(StandardCursorType.Arrow);
_hideMouseTimer.Stop();
_hideMouseTimer.Start();
}
private void HideMouse()
{
this.Cursor = new Cursor(StandardCursorType.None);
}
}