【问题标题】:How can I get DockPanel to make the last item fill to the bottom and right?如何让 DockPanel 使最后一个项目填充到底部和右侧?
【发布时间】:2019-03-31 12:59:17
【问题描述】:

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

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

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

【问题讨论】:

    标签: wpf xaml fill dockpanel


    【解决方案1】:

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

    我在此处为您提供的示例在 Shell.Xaml 中说明了这种技术:Looking for Prism example of Modules loading themselves into a menu

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

    【讨论】:

      猜你喜欢
      • 2021-05-16
      • 2018-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-21
      • 2011-04-29
      • 2010-10-24
      相关资源
      最近更新 更多