2017-04-24 108 views
2

我已經創建主窗口在此窗口中創建DockPanel中用於等作爲下面主窗口結合用戶控制值,集DockPanel中的寬度和高度作爲相同WPF窗口的寬度和高度

<Window x:Class="WpfApplication2.DMMainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     ResizeMode="NoResize" 
     WindowState="Maximized" 
     WindowStyle="None" 
     WindowStartupLocation="CenterScreen" 
     Height="{Binding SystemParameters.PrimaryScreenHeight}" 
     Width="{Binding SystemParameters.PrimaryScreenWidth}"> 
    <DockPanel Width="1254" Height="1200" HorizontalAlignment="Left" Margin="0,0,0,0" x:Name="mainPanel" VerticalAlignment="Top" /> 
</Window> 

在此代碼你可以看到給定的寬度和高度的dockpanel。我需要這個高度和寬度需要綁定與窗口寬度一樣。我已經使用了實際的寬度和高度,也使用了sizetocontent,但沒有像預期的那樣發生。請給出你的建議。

+1

當作爲頂級容器使用,'DockPanel'會自動補'Window'父。你不應該明確地設置'Width'和'Height'。在上面的代碼中,你似乎強迫'DockPanel'的大小與'Window'大小不同,所以它當然不會達到合適的大小。請更準確地說明你要做什麼代碼,爲什麼你認爲你應該這樣做,以及代碼做什麼。這實際上並不清楚你究竟在問什麼。 –

回答

1

您可以添加Stretch屬性如下,

<DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,0,0" x:Name="mainPanel" /> 

希望它會工作

+0

感謝arun工作正常 –

+1

看起來像「Arun D」幫助「arun d」?你的另一個自我會一直幫助你。 – macieqqq

+0

我不能抓到你macieqqq –

0
<Window x:Class="WpfApplication2.DMMainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     ResizeMode="NoResize" 
     WindowState="Maximized" 
     WindowStyle="None" 
     WindowStartupLocation="CenterScreen" 
     Height="{Binding SystemParameters.PrimaryScreenHeight}" 
     Width="{Binding SystemParameters.PrimaryScreenWidth}"> 
     <DockPanel x:Name="mainPanel" /> 
</Window> 
+0

試試這個,它會完全適合你的窗口。 –

3

由於您使用的是停靠面板,因此無需明確設置。如果你想要,你可以通過使用最小高度和寬度進一步限制,但不是強制性的。

<Window x:Class="WpfApplication2.DMMainWindow" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      ResizeMode="NoResize" 
      WindowState="Maximized" 
      WindowStyle="None" 
      WindowStartupLocation="CenterScreen" 
      Height="{Binding SystemParameters.PrimaryScreenHeight}" 
      Width="{Binding SystemParameters.PrimaryScreenWidth}"> 
      <DockPanel x:Name="mainPanel" 
         MinHeight ="{Binding SystemParameters.PrimaryScreenHeight}" 
         MinWidth ="{Binding SystemParameters.PrimaryScreenWidth}" /> 

</Window> 
+0

感謝Simsons工作正常 –