2009-07-29 65 views
1

在我的Shell.xaml中,我希望两个模块各占用一半高度并可扩展。为什么第一个模块被切断?为什么我的模块不能填充Shell.xaml中的完整DockPanel?

alt text http://i30.tinypic.com/2cr5zx0.png

外壳:

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

HelloWorldView:

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

SecondView:

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

回答

1

请允许我回答这个问题。我用了一个Grid变量行高,它的工作。

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

奇怪尽管这StackPanel中DockPanel中不会自动将其向上的空间也同样。

+0

您实际上不需要Height =“5 *”中的5,只需在两行中使用*即可。 – Carlo 2009-07-30 19:40:49

0

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

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

相关问题