tags:

views:

29

answers:

1

I have WPF window with several textboxes, buttons, and canvas where I draw a graph. I would like to have cross cursor over the canvas, because this way user could point interesting area in more "scientific" way :-)

Oddly, when I set cursor to cross for a canvas, it is still a standard arrow instead, but when the mouse is over any line or polyline I drew on the canvas it is cross.

So how to set the cursor for entire canvas (including "empty" space, where nothing is drawn)?

+1  A: 

To change a mouse cursor shape for entire canvas add a transparent background to your canvas.

Here is a sample:

<Canvas Grid.Row="2" Background="Transparent">
   <Polyline Points="25,25 0,50 25,75 50,50 25,25 25,0" 
             Stroke="Blue" StrokeThickness="10"
             Canvas.Left="75" Canvas.Top="50">
      <Polyline.RenderTransform>
          <RotateTransform CenterX="0" CenterY="0" Angle="45" />
      </Polyline.RenderTransform>
   </Polyline>
   <Canvas.Style>
       <Style TargetType="{x:Type Canvas}">
          <Style.Triggers>
              <Trigger Property="IsMouseOver" Value="True" >
                <Setter Property="Cursor" Value="Cross" />
              </Trigger>
          </Style.Triggers>
        </Style>
   </Canvas.Style>
</Canvas>
Zamboni
Thank you very much! Btw. setting cursor is much simpler -- Cursor="Cross" in Canvas tag.
macias