开发者

How to change a mouse cursor shape for entire canvas?

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)?


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜