Visual Studio 2010 SP1设计时的呈现方式与运行时不同

时间:2014-10-23 10:01:17

标签: c# wpf visual-studio-2010 visual-studio-2013 designer

我有一个相当简单的wpf窗口,格式为:

<Window>
    <Canvas>
        <Grid>
            <ListBox />
        </Grid>
    </Canvas>
</Window>

在设计时,一切看起来都像我想要的那样。任何窗口控件都没有自动调整大小。 但是在运行时,Window的底部和右侧有额外的空白区域。

如果我在Visual 2013中打开解决方案,我可以在设计器中看到这个额外的空白区域。

有没有人遇到过这个?我无法在线查找任何内容或Microsoft发布的任何修补程序。

如果我更改窗口大小以使其边框小于其中的控件,那么它在运行时看起来很好。如果我在2013年打开这个项目,设计师的一切看起来都很好。所有控件都在边框内。

注意:我坚持使用2010年作为我们大多数项目的设计。我也是WPF的新手。

enter image description here

完整的XAML:

<Window x:Class="ManageClosedChecks.ClosedCheckList"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        WindowStyle="None" Title="" Height="461" Width="772" Topmost="True" ShowInTaskbar="False" Name="Window" ResizeMode="NoResize" WindowStartupLocation="CenterOwner" Loaded="Window_Loaded" AllowsTransparency="True" BorderBrush="Black" BorderThickness="3">

    <Window.Resources>
        <Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
            <Setter Property="MinWidth" Value="75" />
            <Setter Property="Width" Value="75" />
        </Style>
    </Window.Resources>

    <Canvas Height="461" HorizontalAlignment="Left" Margin="0,0,0,0" Name="canvas1" VerticalAlignment="Top" Width="746">
    <Grid Height="458" Width="746" Background="Transparent" Canvas.Top="0">
        <Button Content="Reprint" Height="41" HorizontalAlignment="Left" Margin="14,411,0,0" Name="ReprintBtn" VerticalAlignment="Top" Width="109" Click="ReprintBtn_Click" IsEnabled="False" />
        <Button Content="Adjust" Height="41" HorizontalAlignment="Left" Margin="143,411,0,0" Name="AdjustBtn" VerticalAlignment="Top" Width="109" Click="AdjustBtn_Click" IsEnabled="False" />
        <Button Content="CANCEL" Height="41" HorizontalAlignment="Right" Margin="0,411,91,0" Name="CancelBtn" VerticalAlignment="Top" Width="109" Click="CancelBtn_Click" />
        <Button Content="Re-Open" Height="41" HorizontalAlignment="Left" IsEnabled="False" Margin="413,411,0,0" Name="reopenBtn" VerticalAlignment="Top" Width="109" Click="reopenBtn_Click" />
        <Button Content="Void" Height="41" HorizontalAlignment="Right" IsEnabled="False" Margin="0,411,354,0" Name="voidBtn" VerticalAlignment="Top" Width="109" Click="voidBtn_Click" />
        <Button FontFamily="Marlett" FontSize="70" Content="5" Height="186" HorizontalAlignment="Left" Margin="661,45,0,0" Name="UpBtn" VerticalAlignment="Top" Width="85" Click="UpBtn_Click" />
        <Button FontFamily="Marlett" FontSize="70" Content="6" Height="175" HorizontalAlignment="Left" Margin="661,0,0,50" Name="DownBtn" VerticalAlignment="Bottom" Width="85" Click="DownBtn_Click" />

        <ListView ScrollViewer.VerticalScrollBarVisibility="Visible" Height="363" HorizontalAlignment="Left" Name="listView1" VerticalAlignment="Top" Width="659" FontSize="18" HorizontalContentAlignment="Left" SelectionMode="Single" Margin="0,45,0,0">
            <ListView.View>
                <GridView AllowsColumnReorder="False">
                    <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding CheckNum}" >
                        <GridViewColumn.Header>
                            <GridViewColumnHeader Tag="CheckNum" Click="lvUsersColumnHeader_Click">Check</GridViewColumnHeader>
                        </GridViewColumn.Header>
                    </GridViewColumn>
                    <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding ClosedDateTime, StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}">
                        <GridViewColumn.Header>
                            <GridViewColumnHeader Tag="ClosedDateTime" Click="lvUsersColumnHeader_Click">Closed Date Time</GridViewColumnHeader>
                        </GridViewColumn.Header>
                    </GridViewColumn>
                    <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding CheckID}">
                        <GridViewColumn.Header>
                            <GridViewColumnHeader Tag="CheckID" Click="lvUsersColumnHeader_Click">Check ID</GridViewColumnHeader>
                        </GridViewColumn.Header>
                    </GridViewColumn>
                    <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding Amount}">
                        <GridViewColumn.Header>
                            <GridViewColumnHeader Tag="Amount" Click="lvUsersColumnHeader_Click">Amount</GridViewColumnHeader>
                        </GridViewColumn.Header>
                    </GridViewColumn>
                    <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding Employee}">
                        <GridViewColumn.Header>
                            <GridViewColumnHeader Tag="Employee" Click="lvUsersColumnHeader_Click">Employee</GridViewColumnHeader>
                        </GridViewColumn.Header>
                    </GridViewColumn>
                    <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding TableNum}">
                        <GridViewColumn.Header>
                            <GridViewColumnHeader Tag="TableNum" Click="lvUsersColumnHeader_Click">Table</GridViewColumnHeader>
                        </GridViewColumn.Header>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>
        </Grid>
    </Canvas>
</Window>

1 个答案:

答案 0 :(得分:3)

设置窗口的SizeToContent属性,并手动删除窗口的给定宽度和高度属性。

SizeToContent="WidthAndHeight"

删除Height="461" Width="772">

然后它看起来像:

VS2010中的设计窗口:

enter image description here

运行时:

enter image description here