I added 开发者_运维问答some polylines on a canvas and registered an event handler for zoom on this canvas, but zooming only works when the mouse is exactly over the polyline. How can I make zooming work when the mouse is somewhere else on the canvas?
Have you set a background on your Canvas? Mouse events are generally only picked up on elements that have a background.
To pick up events a Canvas must have:
- A size - By default, a canvas has no size (perhaps a Height and Width of 0 would be more accurate), though it can have child objects that extend beyond its boundaries. Putting child objects into a Canvas (unlike a Grid or other Panel) does not automatically resize the panel to fit the content.
- A background - This can be transparent (Any Background with Opacity="0" or Background="#00FFFFFF").
Some events may also require that the Handled property of the event args be set to false to allow the event to cascade from the object you clicked (the Polyline in this case) to the Canvas itself. Doesn't sound like you're having that problem, but I mention it in case it becomes an issue later.
精彩评论