How to resize a Canvas in WPF?

后端 未结 3 1582
渐次进展
渐次进展 2021-01-19 06:58

I\'m writing a WPF app that has a Canvas in it. This canvas will be custom rendered at runtime. It\'s sort of like a game in that it needs to be measured in pix

3条回答
  •  天命终不由人
    2021-01-19 07:56

    Any elements positioned in a canvas will not resize or reposition based upon the size of the canvas. So I don't think there's any advantage to setting the size of the canvas. Maybe you should just set a fixed size of the window instead.

    Otherwise, just set the Canvas.Width, Height, and ClipToBounds=True and you have a fixed sized canvas that positions its child elements with X/Y coordinates.

    Also you should be sure to set SnapsToDevicePixels=True on the canvas so that child elements will have crisp pixel-aligned bounds.

提交回复
热议问题