Finally, he managed it under WPF without using WinForms or PInvokes. Instead of creating custom cursors (* .cur) on the fly or converting Visual to cursors, I used the MouseMove event of the parent control along with the WPF ( Path ) element as my cursor. Here's the way, just in case anyone is interested:
- Set the
Cursor your large size (or what you use as the border of your figure) to None so that WPF does not display the default arrow. Create your own cursor. It can be any FrameworkElement , but I used Path to easily process it to create whatever shape you want. Please note that most of the properties that I set below are important.
<Path x:Name="PART_EW" Data="M0,20 L25,0 25,15 75,15 75,0 100,20 75,40 75,25 25,25 25,40z" Fill="White" Stroke="Black" StrokeThickness="1" Visibility="Collapsed" Width="50" Height="20" Opacity=".7" Stretch="Fill" Panel.ZIndex="100001" HorizontalAlignment="Left" VerticalAlignment="Top" IsHitTestVisible="False" />
Add the following code to your large size:
protected override void OnMouseEnter(MouseEventArgs e) { base.OnMouseEnter(e); var Pos = e.GetPosition(this); PART_EW.Margin = new Thickness( Pos.X - PART_EW.Width / 2, Pos.Y - PART_EW.Height / 2, -PART_EW.Width, -PART_EW.Height); PART_EW.Visibility = Visibility.Visible; } protected override void OnMouseLeave(MouseEventArgs e) { base.OnMouseLeave(e); PART_EW.Visibility = Visibility.Collapsed; } protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); var Pos = e.GetPosition(designerItem); PART_EW.Margin = new Thickness( Pos.X - PART_EW.Width / 2, Pos.Y - PART_EW.Height / 2, -PART_EW.Width, -PART_EW.Height); }
Please note that I did not set the RotateTransform my Path anywhere in the code, as it is already part of a large size and therefore automatically gets the angle of the parent control.
Hope this helps people in the future.
source share