Custom cursors in Avalon


So, how do you create a custom cursor in Avalon? The most straightforward way is to reference it from a file, but there are also constructor overloads that a Stream argument and an IntPtr argument (in case you have a raw handle).


MyWindow.Cursor = new Cursor(@"C:\WINDOWS\Cursors\stopwtch.ani");


What can you do with cursors? Well, a Cursor is a dependency property, declared in FrameworkElement, so you can use it with XAML, with styles, and everywhere where there is dependency property goodness. This little sample shows how to load a custom cursor from a file, and how to use one of the built-in cursors.


<DockPanel xmlns="http://schemas.microsoft.com/winfx/avalon/2005">
 <Border BorderBrush='Green' BorderThickness='1' Padding='2' Margin='2'>
  <TextBlock Cursor='c:\windows\cursors\stopwtch.ani'>
   Wait - oh yes, wait a minute Mr. Postman!
  </TextBlock></Border>
 <Border BorderBrush='Blue' BorderThickness='1' Padding='2' Margin='2'>
  <TextBlock Cursor='Pen'>Built-in cursors are also supported.</TextBlock>
 </Border>
</DockPanel>


Comments (2)

  1. Alejandro says:

    "Funny" shaped cursors are baaack!

    😉

  2. Putting Constants in your XAML File? x:Static Is Your Friend.

    Building an Avalon application: Part…

Skip to main content