对于任何应用程序而言,一个常见的任务是调整光标以指示当前应用程序正处于繁忙状态或不同空间显示不同的光标。我们可以为任何元素设置Cursor属性。
通过代码改变窗体鼠标光标
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfApplication1 { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); this.Cursor = Cursors.Wait; } } }
为某个空间设置鼠标光标
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <TextBlock FontSize="12" Width="100" Height="50" Cursor="ArrowCD">123</TextBlock> </Grid> </Window>