为什么我的 WPF 窗口大小默认很大 [英] Why are my WPF window sizes defaulting to be huge

查看:19
本文介绍了为什么我的 WPF 窗口大小默认很大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有几个表单的 wpf 应用程序.在设计时它们很小,并且它们没有设置为自动大小.然而在运行时它们是巨大的,即使它们中没有内容使它们变大.

I have a wpf application with a few forms. At design time they are small, and they are not set to auto size. However at run time they are giant, even with no content in them to make them big.

为什么会这样?

这是其中一种形式

<Window x:Class="SuperPluginPicker"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:tree="clr-namespace:Aga.Controls.Tree;assembly=Aga.Controls" 
             mc:Ignorable="d" 
             d:DesignHeight="296" d:DesignWidth="634" Title="Plugin Selector" WindowStartupLocation="CenterOwner">
    <Grid>
        <DockPanel LastChildFill="true">
            <StackPanel DockPanel.Dock="Bottom" Height="30" Orientation="Horizontal">
                <Button Content="Ok" Name="btnOk" Click="btnOk_Click"></Button>
                <Button Content="Cancel" Name="btnCancel" Click="btnCancel_Click"></Button>

            </StackPanel>
            <StackPanel DockPanel.Dock="Right">
                <Label Content="Selected Plugins"></Label>
            <ListBox Name="lstSelectedPlugins"  Width="200">
                <ListBox.ItemTemplate>



                    <DataTemplate>



                        <Label Content="{Binding Name}" />

                    </DataTemplate>

                </ListBox.ItemTemplate>

            </ListBox>
            </StackPanel>
            <StackPanel DockPanel.Dock="Right" Width="100" VerticalAlignment="Center">
                <Button Content="Add" Name ="btnAdd" Click="btnAdd_Click"></Button>
                <Button Content="Remove" Name="btnRemove" Click="btnRemove_Click"></Button>
                <Button Content="Remove All" Name="btnRemoveAll" Click="btnRemoveAll_Click"></Button>
            </StackPanel>

            <tree:TreeList  x:Name="pluginTree">
                <tree:TreeList.View>
                    <GridView x:Name="treeGrid">
                        <GridView.Columns>

                            <GridViewColumn Width="Auto" Header="Name">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <tree:RowExpander/>

                                            <TextBlock Text="{Binding Name}"></TextBlock>
                                        </StackPanel>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Header="Author" Width="Auto"  DisplayMemberBinding="{Binding Author}"/>
                            <GridViewColumn Header="Description" Width="Auto" DisplayMemberBinding="{Binding Type}"/>


                        </GridView.Columns>
                    </GridView>
                </tree:TreeList.View>
            </tree:TreeList>
        </DockPanel>
    </Grid>
</Window>

推荐答案

如果您使用此代码创建 :

If you create a <Window/> with this code:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />

然后,当您从 Visual Studio 运行它时,它将显示一个与您在问题中放置的窗口大小相同的窗口.所以这不是你明确做的任何事情.

Then when you run that from Visual Studio it will display a window the same size as the one you put in your question. So this isn't anything you explicitly did.

您遇到的是 WPF Window 的默认计算大小.对于不同的结果,请在窗口上指定 SizeToContent 参数,正如 paxdiablo 指出的那样,或者使用 MinHeightMaxHeight 明确设置窗口的大小>、HeightMinWidthMaxWidth 和/或 Width 属性.

What you've encountered is the default computed size of a WPF Window. For different results, specify a SizeToContent parameter on the Window, as paxdiablo pointed out, or explicitly set the size of your window with the MinHeight, MaxHeight, Height, MinWidth, MaxWidth, and/or Width properties.

这篇关于为什么我的 WPF 窗口大小默认很大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆