子元素的大小不适合父WPF

时间:2015-03-09 08:32:12

标签: wpf xaml

我正面临以下问题。我将主窗口定义为

<Window x:Class="WpfApplication6.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="650" Width="500"
    xmlns:local="clr-namespace:WpfApplication6">
<Grid>
    <local:UserControl1></local:UserControl1>
</Grid>

和UserControl1如下:

<UserControl x:Class="WpfApplication6.UserControl1"
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" 
mc:Ignorable="d" Width="500" Height="650">

两者的宽度和高度是相同的,所以我希望看到整个视图UserControl,但事实证明它超出了父母的大小。

enter image description here

是因为窗口高度和宽度是否包含边框?

1 个答案:

答案 0 :(得分:0)

窗口的高度和宽度包括边框和标题栏。

一般情况下:不要使用绝对尺寸,而是使用拉伸,而不是通过将Horizo​​ntal / VerticalAlignment设置为拉伸或嵌套在网格中。

要在Visual Studio设计器中调整元素大小,请使用d:DesignWidthd:DesignHeight。这些不会影响应用程序运行时的UI。