0

如何让底部文本块水平和垂直填充剩余空间?

替代文字

我有一个有这个区域的外壳:

<DockPanel Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" LastChildFill="True"  
Background="Orange">

    <ItemsControl x:Name="MainNavigationPanel" 
        Background="Yellow"
        DockPanel.Dock="Left"
        cal:RegionManager.RegionName="MainNavigationPanel"
            Width="200" 
            HorizontalAlignment="Left"/>


    <StackPanel x:Name="MainContent"
        Background="Beige"
        Width="Auto"
        Height="Auto"
        VerticalAlignment="Stretch"
        HorizontalAlignment="Stretch"
        >
        <TextBlock Text="This will be the main region content."/>
        </StackPanel>

</DockPanel>

MainNavigationPanel我加载这个视图:

<UserControl x:Class="MenuModule.Views.MainNavigationView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:igOB="http://infragistics.com/OutlookBar"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    VerticalAlignment="Stretch" 
    HorizontalAlignment="Stretch">

    <DockPanel LastChildFill="True"
        Background="Red"
        HorizontalAlignment="Left"
        VerticalAlignment="Stretch">

            <TextBlock Text="first" 
            DockPanel.Dock="Top"
            Background="LightBlue"
            VerticalAlignment="Stretch"
            HorizontalAlignment="Stretch"/>

            <TextBlock Text="second" 
            DockPanel.Dock="Bottom"
            Background="LightGreen"
            VerticalAlignment="Stretch"
            HorizontalAlignment="Stretch"/>

    </DockPanel>

</UserControl>
4

1 回答 1

2

Dockpanel 将使用最后一个没有指定 DockPanel.Dock 附加属性和指定高度/宽度的项目自动填充剩余空间。

我在此处为您提供的示例在 Shell.Xaml 中说明了这种技术: 寻找将自身加载到菜单中的模块的 Prism 示例

您还可以在 DockPanel 的“备注”部分的 MSDN 文档中找到这一事实:MSDN 上的 DockPanel

于 2009-07-22T15:34:11.260 回答