2014-01-15 65 views
0

我有一個選項卡控件,它動態填充包含各種大小的用戶控件的選項卡。當一個標籤被打開時,我希望窗口能夠自動調整大小,使其有效的用戶控制。有沒有一種乾淨的方式來做到這一點?WPF - 將窗口大小設置爲child usercontrol大小

我使用的是標準mvvm模式。

回答

4

使用SizeToContent屬性窗口類。

<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" 
     SizeToContent='Width'> 
    <Grid> 
    <Button Width='200' Content='The Button' /> 
    </Grid> 
</Window> 
+0

效果很好,使用'widthandheight'選項來設置sizetocontent – rcj