1

在我的 Shell.xaml 中,我希望两个模块各占一半高度并且可以扩展。为什么第一个模块被切断?

替代文字

贝壳:

<Window x:Class="HelloWorld.Desktop.Shell"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:cal="http://www.codeplex.com/CompositeWPF"
        Height="300"
        Width="300"
        Title="Hello World" >

    <DockPanel LastChildFill="True">
        <ContentControl Name="MainRegion" 
                        DockPanel.Dock="Top"
                 cal:RegionManager.RegionName="MainRegion"/>
        <ContentControl 
            Name="SecondRegion" 
            DockPanel.Dock="Top"
            cal:RegionManager.RegionName="SecondRegion"/>
    </DockPanel>
</Window>

你好世界视图:

<UserControl x:Class="HelloWorldModule.Views.HelloWorldView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <StackPanel
            Background="Tan">
        <TextBlock Text="Hello World View"
                   Foreground="Brown"
                   Margin="10 10 10 0"
                   FontSize="14"/>

        <TextBlock Name="DisplayArea" 
                 Margin="10 10 10 0" Text="(default text)" TextWrapping="Wrap"/>
    </StackPanel>
</UserControl>

第二视图:

<UserControl x:Class="SecondModule.Views.SecondView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <StackPanel
            Background="Orange">
        <TextBlock Text="Second View"
                   Foreground="Brown"
                   Margin="10 10 10 0"
                   FontSize="14"/>

        <TextBox Name="Message" 
                 Margin="10 10 10 0" Text="skfddsf" TextChanged="TextBox_TextChanged"/>
    </StackPanel>
</UserControl>
4

2 回答 2

1

请允许我回答这个问题。我使用了具有可变行高的网格并且它有效。

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="5*"/>
        <RowDefinition Height="5*"/>
    </Grid.RowDefinitions>
    <ContentControl Name="MainRegion" 
                    Grid.Row="0"
             cal:RegionManager.RegionName="SecondRegion"/>
    <ContentControl 
        Name="SecondRegion" 
                    Grid.Row="1"
        cal:RegionManager.RegionName="MainRegion"/>
</Grid>

奇怪的是StackPanelDockPanel不会自动平均分配它们的空间。

于 2009-07-29T11:53:52.593 回答
0

StackPanel 不会拉伸其子项以填充可用空间(这是一项功能)。

如果您使用 DockPanel 会拉伸LastChildFill="true"

于 2009-07-29T11:56:57.373 回答