[英]Last component of User Control doesn't fill the available space on the hosting grid
我正在开发C#wpf项目,但遇到了问题。 我有一个承载网格的主窗口。 该网格托管一个用户控件,而该用户控件以3列布局托管3个DockPanel。
3列可通过工作的网格拆分器进行调整,但是右侧列未填充“主窗口”网格的可用空间。
以下是托管用户控件的主窗口的XAML:
<Window x:Class="Boardies_Email_Client.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Boardies_Email_Client"
mc:Ignorable="d"
Title="MainWindow" Height="350" WindowStartupLocation="CenterScreen" ResizeMode="CanResizeWithGrip" WindowState="Maximized">
<Grid>
<Grid x:Name="GridHost" Margin="0" Background="#FFF3FF00"/>
<StatusBar Height="24" VerticalAlignment="Bottom"/>
</Grid>
</Window>
下面是用户控件的XAML
<UserControl x:Class="Boardies_Email_Client.EmailClient"
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"
xmlns:local="clr-namespace:Boardies_Email_Client"
mc:Ignorable="d"
d:DesignHeight="505">
<Grid HorizontalAlignment="Left" Width="1120">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="92*"/>
<ColumnDefinition Width="121*"/>
<ColumnDefinition Width="87*"/>
<ColumnDefinition Width="225*"/>
<ColumnDefinition Width="134*"/>
<ColumnDefinition Width="116*"/>
<ColumnDefinition Width="345*"/>
</Grid.ColumnDefinitions>
<DockPanel Background="#FFEC1717" Grid.ColumnSpan="2">
<Label x:Name="label" Content="My Label" Margin="0,0,0,460" Width="175"/>
</DockPanel>
<GridSplitter x:Name="gridSplitter" HorizontalAlignment="Left" Width="5" Grid.Column="2"/>
<DockPanel LastChildFill="False" Margin="5,0,0,0" Background="#FF5DFF00" Grid.Column="2" Grid.ColumnSpan="3"/>
<GridSplitter x:Name="gridSplitter1" HorizontalAlignment="Left" Width="5" Grid.Column="5"/>
<DockPanel Grid.Column="5" Margin="5,0,0,0" Background="#FF0A00E2" Grid.ColumnSpan="2"/>
</Grid>
</UserControl>
下面是显示问题的屏幕截图
红色,绿色和蓝色是被网格拆分器分隔的扩展坞面板。 黄色是托管用户控件的主窗口网格的背景色,蓝色面板应填充黄色的可用空间,但我看不出为什么不是这样。
我没有设定任何可以找到的宽度。
@董事会
我运行了您的代码。 用户控件的拆分和网格的组织很好。
但是您将宽度设置为固定大小:
<UserControl ...>
<Grid HorizontalAlignment="Left" Width="1120">
如果删除固定大小,则一切都很好,该控件将获取窗口的大小,并且对于大于1120的大小,您不会在右侧看到其他背景(黄色或右侧):
<UserControl ...>
<Grid >
问候
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.