如何让DockPanel将最后一项填入底部和右侧?

时间:2023-02-09 18:09:18

How do I get the bottom textblock to fill up the remaining space horizontally and vertically?

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

alt text http://i28.tinypic.com/ra5c1g.png

alt text http://i28.tinypic.com/ra5c1g.png

I've got a shell that has this region:

我有一个有这个区域的shell:

<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>

And in MainNavigationPanel I load this view:

在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>

1 个解决方案

#1


Dockpanel will automatically fill in the remaining space with the last item that does not have a DockPanel.Dock attached property specified and a Height/Width specified.

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

The sample I provided for you here illustrates this technique in the Shell.Xaml: Looking for Prism example of Modules loading themselves into a menu

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

You can also find this fact in the MSDN documentation in the "Remarks" section for a DockPanel: DockPanel on MSDN

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

#1


Dockpanel will automatically fill in the remaining space with the last item that does not have a DockPanel.Dock attached property specified and a Height/Width specified.

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

The sample I provided for you here illustrates this technique in the Shell.Xaml: Looking for Prism example of Modules loading themselves into a menu

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

You can also find this fact in the MSDN documentation in the "Remarks" section for a DockPanel: DockPanel on MSDN

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