Visual Studio 2010 WPF 设计器规模

发布于 2024-09-28 06:38:27 字数 1590 浏览 2 评论 0原文

我在 Visual Studio 2010 中制作了简单的界面。当我启动应用程序时,一切都变得更大。屏幕截图上的红色方块代表启动应用程序中按钮的大小(右侧)。 我错过了什么吗?如何修复它?

聚苯乙烯 在“Microsoft Expression Blend 4”中,同一项目的大小与编辑器中的大小完全相同。


Windows缩放滑块


<Window x:Class="WpfControlReview.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Height="120" Width="256" ResizeMode="NoResize">
    <Grid>
        <Button HorizontalAlignment="Stretch" Name="button1" VerticalAlignment="Stretch">
        <StackPanel HorizontalAlignment="Stretch" Name="stackPanel1" VerticalAlignment="Center">
            <Label IsHitTestVisible="False" Content="Select your options and press to commit" Name="label1" HorizontalContentAlignment="Center" FontSize="12" />
            <StackPanel Name="stackPanel2" Orientation="Horizontal">
                <Expander Header="Color" Name="expander1">
                </Expander>
                <Expander Header="Make" Name="expander2">
                </Expander>
                <Expander Header="Payment" Name="expander3">
                </Expander>
            </StackPanel>
        </StackPanel>
        </Button>
    </Grid>
</Window>

I made simple interface in Visual Studio 2010. When I launched application everything is bigger. Red square on screenshot represents size of the Button in launched application (On the right).
Am I missing something? How to fix it?

P.S.
In "Microsoft Expression Blend 4" the same project is exactly the same size as in editor.


WindowsScale Slider


<Window x:Class="WpfControlReview.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Height="120" Width="256" ResizeMode="NoResize">
    <Grid>
        <Button HorizontalAlignment="Stretch" Name="button1" VerticalAlignment="Stretch">
        <StackPanel HorizontalAlignment="Stretch" Name="stackPanel1" VerticalAlignment="Center">
            <Label IsHitTestVisible="False" Content="Select your options and press to commit" Name="label1" HorizontalContentAlignment="Center" FontSize="12" />
            <StackPanel Name="stackPanel2" Orientation="Horizontal">
                <Expander Header="Color" Name="expander1">
                </Expander>
                <Expander Header="Make" Name="expander2">
                </Expander>
                <Expander Header="Payment" Name="expander3">
                </Expander>
            </StackPanel>
        </StackPanel>
        </Button>
    </Grid>
</Window>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧街凉风 2024-10-05 06:38:27

我不确定这是否是一个错误,但这里的基本思想是您已经为窗口指定了默认大小,但因为控件想要更大(无论出于何种原因),它会自动调整窗口大小。可能是 Visual Studio 使用指定参数计算设计器中窗口边框大小的错误,因为它错误地将其显示为比实际启动应用程序时小一点。

我宁愿建议您尽可能避免指定高度/宽度。而是将窗口设置为 SizeToContent=WidthAndHeight。如果您需要调整控件的大小,请直接在控件上设置边距或最小宽度/最小高度。

I'm not sure if this is a bug or not, but the basic idea here is that you have specifed a default size for your window, but because the control wants to be bigger (for whatever reason) it will automatically resize the window. Could be a bug how Visual Studio calculates window border size in the designer with the specified parameters as it's incorrectly showing it as a bit smaller than when you actually launch your application.

I would rather suggest that you avoid specifying heights/widths if possible. Instead set the Window to SizeToContent=WidthAndHeight. If you need to play with the size of your controls use Margins or MinWidth/MinHeight set directly on your controls.

将军与妓 2024-10-05 06:38:27

您是否缩小了视觉工作室设计师的范围?检查左侧的轨迹栏并上下滚动以放大和缩小。

Are you zoomed out in the visual studio designer? Check the trackbar to your left and scroll it up and down to zoom in and out.

亚希 2024-10-05 06:38:27

请记住,WPF 会缩放 UI。你玩过 DPI 设置吗?这将影响 UI 组件在显示屏上的渲染。尝试在辅助计算机上运行该应用程序以消除显示问题。

来自 MSDN:

与分辨率无关并且
与设备无关的图形。基本的
WPF 中的测量单位
图形系统是设备
独立像素,是1/96
一英寸,无论实际屏幕如何
分辨率,并提供
分辨率无关的基础
和设备无关的渲染。每个
自动独立于设备的像素
缩放以匹配每英寸点数
(dpi) 所渲染系统的设置
上。

http://msdn.microsoft.com/en-us/library/aa970268.aspx

Remeber that WPF scales the UI. Have you played with your DPI settings at all? This will affect the render of the UI componets on the display. Try running the app on a secondary machine to eleimate display issues.

From MSDN:

Resolution-independent and
device-independent graphics. The basic
unit of measurement in the WPF
graphics system is the device
independent pixel, which is 1/96th of
an inch, regardless of actual screen
resolution, and provides the
foundation for resolution-independent
and device-independent rendering. Each
device-independent pixel automatically
scales to match the dots-per-inch
(dpi) setting of the system it renders
on.

http://msdn.microsoft.com/en-us/library/aa970268.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文