橡胶窗WPF

时间:2015-05-12 21:30:32

标签: c# wpf

我创建了设置高度和宽度的窗口。当前内容放在窗口中。但是当我改变内容时,之前它并没有放在窗口中。如何创建橡胶窗口谁自动改变所需的尺寸?

<Window x:Class="GidroTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:gidro_test="clr-namespace:GidroTest"
        Title="MainWindow" Height="200" Width="200"
        WindowStartupLocation="CenterScreen"
        >
    <DockPanel>
          <!-- Before click -->
        <Rectangle Width="199" Height="199" Click="Change_size_Click"/>
        <!-- After click -->
        <Rectangle Width="300" Height="300" Click="Change_size_Click"/>
    </DockPanel>        
</Window>

1 个答案:

答案 0 :(得分:1)

您可以尝试将SizeToContent设置为:WidthAndHeightWidthHeight,不要忘记删除HeightWidth来自Window

<Window SizeToContent="WidthAndHeight">

详细信息:https://msdn.microsoft.com/en-us/library/system.windows.window.sizetocontent%28v=vs.110%29.aspx