简体   繁体   English

VS 2013 Wpf视觉错误?

[英]VS 2013 Wpf visual bug?

After reading some stuff on the internet I decided to try switch from C#+Windows forms to C#+WPF. 阅读了互联网上的一些内容后,我决定尝试从C#+ Windows窗体切换到C#+ WPF。 But I ran into some weird stuff (bug? invalid installation?): in editor everything looks fine and nice, but when I build it - it looks noticeably different from what I see in editor (for example: even though I set borders thickness to 0 - they are still present and ignore this setting overall). 但是我遇到了一些奇怪的问题(错误?安装无效吗?):在编辑器中,一切看起来都很好,但是,当我构建它时,它看起来与我在编辑器中看到的明显不同(例如:即使我将边框的粗细设置为0-它们仍然存在,整体上忽略此设置)。

Any way to fix it? 有什么办法解决吗?

Here is code I'm using (I'm not using anything specific, just some menus and buttons). 这是我正在使用的代码(我没有使用任何特定的东西,只是一些菜单和按钮)。

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" ResizeMode="CanResizeWithGrip">
<Window.Effect>
    <DropShadowEffect RenderingBias="Quality"/>
</Window.Effect>
    <DockPanel>
        <Menu DockPanel.Dock="Top">
            <MenuItem Header="_File">
                <MenuItem Header="_Generate new"/>
                <MenuItem Header="_Export"/>
                <MenuItem Header="_Import"/>
                <Separator/>
                <MenuItem Header="E_xit"/>
            </MenuItem>
            <MenuItem Header="_Test"/>
        </Menu>
        <Grid>    
            <Button Content="Button" HorizontalAlignment="Left" Margin="432,289,0,0" VerticalAlignment="Top" Width="75"/>
            <Button Content="Button" HorizontalAlignment="Left" Margin="352,289,0,0" VerticalAlignment="Top" Width="75"/>
            <GroupBox Header="GroupBox" HorizontalAlignment="Left" Margin="10,35,0,0" VerticalAlignment="Top" Height="110" Width="123"/>

        </Grid>
    </DockPanel>
</Window>

Here is capture to help better understand question. 这里是捕获以帮助更好地理解问题。 在此处输入图片说明

You probably built your window by using what you learned with Forms: you dragged and dropped controls. 您可能通过使用从Forms中学到的东西来构建窗口:拖放控件。 This will result in suboptimal results in WPF. 这将导致WPF中的效果不佳。 WPF has a system of positioning elements that way more advanced than pixel positioning. WPF的定位元素系统比像素定位更为先进。

You should have a look into tutorials about WPF layout. 您应该浏览有关WPF布局的教程。 WPF is a way different beast than WinForms and if you approach it as "WinForms with a funny look" it will not work well. WPF是一种与WinForms不同的野兽,如果您将其称为“具有有趣外观的WinForms”,它将无法正常工作。

Look into WPF layout, container controls and relative positioning. 查看WPF布局,容器控件和相对位置。 If you see any absolute values in your XAML, it's probably not perfect. 如果您在XAML中看到任何绝对值,则可能并不完美。

Example: 例:

Margin="432,289,0,0"

That's bad. 那很糟。 It's absolute positioning. 这是绝对的定位。 It does not care how large the window is or how large the borders are. 它不在乎窗口有多大或边框有多大。 The control is placed 432/289 from the upper left. 控件从左上方放置432/289。 That's what you see. 那就是你所看到的。 The distance from the upper left is kept, but as your window is influenced by your windows style, it looks not like your want it to look. 与左上角的距离保持不变,但是由于您的窗口受窗口样式的影响,因此看起来不像您希望的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM