using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Markup;
namespace CustomCursor
{
public class CustomCursor : Control
{
private const string cursorTemplate =
"<ControlTemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" " +
"xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">" +
"<Image x:Name=\"MyCursor\">" +
"</Image>"+
"</ControlTemplate>";
Image _cursor;
string _cursorResource;
public CustomCursor(string resource)
{
_cursorResource = resource;
Template = (ControlTemplate)XamlReader.Load(cursorTemplate);
ApplyTemplate();
}
public override void OnApplyTemplate()
{
_cursor = (Image) GetTemplateChild("MyCursor");
Uri uri = new Uri(_cursorResource, UriKind.Relative);
ImageSource imgSrc = new System.Windows.Media.Imaging.BitmapImage(uri);
_cursor.Source = imgSrc;
}
public void MoveTo(Point pt)
{
this.SetValue(Canvas.LeftProperty, pt.X);
this.SetValue(Canvas.TopProperty, pt.Y);
}
}
}