WPF 窗口在运行时挤压
我在 Visual Studio 2010 中设计了一个 WPF 窗口,其中包含多个控件。该窗口被设置为程序启动的默认窗口。该窗口的大小足以让所有控件正确安装。
当我执行程序时,由于某种原因,窗口开始时比设计器中显示的尺寸小得多,并且控件不适合。如何解决这个问题?
窗口打开代码如下:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
Title="Main" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="548" d:DesignWidth="924" SizeToContent="WidthAndHeight" xmlns:my="clr-namespace:ElanceTracker" WindowStartupLocation="CenterScreen" xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors" xmlns:lc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol" xmlns:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon" xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars" xmlns:dxn="http://schemas.devexpress.com/winfx/2008/xaml/navbar" xmlns:dxca="http://schemas.devexpress.com/winfx/2008/xaml/carousel" xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts">
I've designed a WPF window in Visual Studio 2010 with several controls in it. The window is set as default for the program startup. The size of this window is sufficient for all controls to fit properly.
When I execute the program, for some reason the window starts much smaller than the size shown in designer, and controls do not fit. How to troubleshoot this problem?
The window opening code is as follows:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
Title="Main" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="548" d:DesignWidth="924" SizeToContent="WidthAndHeight" xmlns:my="clr-namespace:ElanceTracker" WindowStartupLocation="CenterScreen" xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors" xmlns:lc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol" xmlns:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon" xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars" xmlns:dxn="http://schemas.devexpress.com/winfx/2008/xaml/navbar" xmlns:dxca="http://schemas.devexpress.com/winfx/2008/xaml/carousel" xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试分别更改高度和宽度的 DesignHeight 和 DesignWidth,并将 SizeToContent 设置为 None。
Try changing DesignHeight and DesignWidth for Height and Width respectively, and also, set SizeToContent to None.
您使用了错误的属性。 DesignWidth 和 DesignHeight 仅设置设计时尺寸。您需要宽度和高度。
You are using the wrong attributes. DesignWidth and DesignHeight only set the design time size. You want Width and Height.
这个bug在最新的Visual Studio中仍然存在。
我总是将窗口设计得宽 16 像素、高 16 像素,以便在运行时获得正确的尺寸。
This bug still exist in the newest Visual Studio.
I always design my windows 16 pixels wider and 16 pixels higher to get the right size at run time.