2009-10-15 78 views
0

谁能可能是为了我解释为什么下面的简单示例工程:如何获取在ItemsControl中工作的WPF GridSplitter控件?

<ItemsControl x:Class="UserControl1" 
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <Grid /> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition /> 
      <RowDefinition Height="5" /> 
      <RowDefinition /> 
     </Grid.RowDefinitions> 

     <Grid Background="Yellow" /> 

     <GridSplitter Grid.Row="1" 
         HorizontalAlignment="Stretch" 
         VerticalAlignment="Stretch" /> 

     <Grid Grid.Row="2" 
       Background="Orange" /> 
    </Grid> 
</ItemsControl> 

...但是当我做ItemsPanelTemplate的主要原因之一,这不:

<ItemsControl x:Class="UserControl1" 
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <Grid> 
       <Grid.RowDefinitions> 
        <RowDefinition /> 
        <RowDefinition Height="5" /> 
        <RowDefinition /> 
       </Grid.RowDefinitions> 
      </Grid> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 

    <Grid Background="Yellow" /> 

    <GridSplitter Grid.Row="1" 
        HorizontalAlignment="Stretch" 
        VerticalAlignment="Stretch" /> 

    <Grid Grid.Row="2" Background="Orange" /> 
</ItemsControl> 

他们都显示器橙色盒子顶部的黄色盒子,它们之间有水平分配器。在第一个例子中,分离器工作正常,可以调整两个区域的大小。在第二个例子中(产生一个几乎相同的视觉树),分离器被锁定,它不会让我拖动它来调整两个区域的大小!

这是我试图实现的一个非常简单的例子 - 但它演示了我在实际应用程序中遇到的问题。我必须错过一些东西,阻碍分离器运作的是什么?所有三个孩子被添加到ItemsPanelTemplate网格确定....

任何解释或修复将不胜感激!

问候, 戴夫

回答

3

哦,没有人回答?这是因为GridSplitter必须是父Grid的直接子节点才能知道列的实际大小。

相关问题