本文介绍了如何调整在WPF中的画布?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个WPF应用程序,有一个画布在里面。这画布会在运行时自定义的渲染。这有点像游戏中,它需要以像素进行测量。我需要能够把我的画布来478x478像素(客户端矩形的大小)。我不希望任何缩放或其他与分辨率无关的步骤,发生在我的画布

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 pixels. I need to be able to set my Canvas to 478x478 pixels (client rectangle size). I don't want any scaling or other resolution-independent steps to take place on my Canvas.

我不知道这是可能的WPF,因为它的性质是独立的分辨率。我的问题:

I'm not sure if this is possible in WPF, since its nature is to be resolution independent. My questions:

  1. 如何调整我的画布在运行时(函数调用?)
  2. 当我调整我的画布,被渲染的区域(客户端矩形)将成为该尺寸?如果没有,我怎么可以调整它的大小,以确保客户的矩形是一个特定的宽/高?
  3. 是否有可能设置画布中的像素宽度/高度?如何WPF的分辨率无关的方面干扰我想要做什么?
  4. 当我调整我的画布,将其他控件调整适当,因为他们的目的是为了做WPF设计?
  1. How do I resize my Canvas at runtime (function to call?)
  2. When I resize my Canvas, is the renderable area (the client rectangle) going to be that size? If not, how can I resize it to make sure the client rectangle is a specific width/height?
  3. Is it possible to set the width/height of the Canvas in Pixels? How does the resolution-independent aspect of WPF interfere with what I'm trying to do?
  4. When I resize my Canvas, will other controls resize appropriately as they have been designed to do in the WPF designer?

在此先感谢。

推荐答案

定位在画布上的任何元素不会调整或根据画布的尺寸复位。因此,我不认为有任何优势来设置画布的大小。也许你应该只设置窗口的固定大小吧。

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.

否则,只需设置Canvas.Width,高度和ClipToBounds =真,你有一个固定大小的画布放置其子元素的X / Y坐标。

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.

另外,你应该确保设置SnapsToDevicePixels = TRUE在画布上,这样子元素将有清晰的像素对齐边界。

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

这篇关于如何调整在WPF中的画布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 07:27
查看更多