0

次の簡単な例が機能する理由を誰かが説明してくれませんか:

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

どちらも、オレンジ色のボックスの上に黄色のボックスが表示され、その間に水平スプリッターがあります。最初の例では、スプリッターが正しく機能し、2 つの領域のサイズを変更できます。2 番目の例 (ほぼ同一のビジュアル ツリーが生成されます) では、スプリッターがロックされているため、スプリッターをドラッグして 2 つの領域のサイズを変更することはできません。

これは、私が達成しようとしていることの非常に単純化された例ですが、実際のアプリで発生している問題を示しています。何か不足しているに違いありません。スプリッターの機能を妨げているのは何ですか? 3 つの子すべてが ItemsPanelTemplate グリッドに追加されます。

説明や修正をいただければ幸いです。

よろしく、デイブ

4

1 に答える 1

4

ああ、誰も答えなかったの?これは、列の実際のサイズを知るために、GridSplitter が親 Grid の直接の子である必要があるためです。

于 2011-01-20T23:30:52.167 に答える