4

GridSplitter を使用してグリッド内のセルのサイズを変更していますが、その動作は期待したものではなく、解決策が見つかりません。これは 3 行のグリッドで、最初の行定義は Auto に設定されており、いくつかの要素が含まれています。2 番目の行にはいくつかのデータがあり、残りのスペースを埋めるために * の行定義があります。最後の行は、サイズ変更が必要なステータス バーであるため、グリッド スプリッターがあり、行定義の高さが Auto で MinHeight が 30 です。

問題は、GridSplitter を一番上までドラッグすると、セルがオーバーフローすることです。頂上に着いたらストップしてほしい。最後の行から Height=Auto を削除することで目的の動作を実現できますが、これにより、一番下のセルが中央の行と同じ高さに拡張されます。

XAML パッドの例を次に示します。

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
    <Grid ShowGridLines="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" MinHeight="20" />
            <RowDefinition Height="Auto" MinHeight="30" />
        </Grid.RowDefinitions>
        <TextBlock Grid.Row="0" Text="Foo" />
        <TextBlock Grid.Row="1" Text="Bar" />
        <GridSplitter  Canvas.ZIndex="1"  VerticalAlignment="Top"  Grid.Row="2" Background="Cyan" Height="5" HorizontalAlignment="Stretch"  />
        <TextBlock VerticalAlignment="Bottom" Grid.Row="2" TextWrapping="Wrap">LOL<LineBreak/>LOL<LineBreak/>LOL</TextBlock>
    </Grid>
</Page>

上にドラッグすると、下のテキストが消えます。

グリッドスプリッターを独自のセルに配置したり、高さを別のオブジェクト ActualHeight にバインドしたりするなど、さまざまなことを試しましたが、実際にはうまく機能しません。

私はそれが最もよく説明された質問ではないことを知っていますが、どんなアイデアでも大歓迎です.

編集: 以下に投稿されているように、独自の行で GridSplitter を作成しましたが、前述したように、問題はまだ残っています。ここでは ResizeBehavior と ResizeDirection も設定しています。

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
    <Grid ShowGridLines="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" MinHeight="20" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" MinHeight="30"  />
        </Grid.RowDefinitions>
        <TextBlock Grid.Row="0" Text="Foo" />
        <TextBlock Grid.Row="1" Text="Bar" />
        <GridSplitter ResizeDirection="Rows" ResizeBehavior="PreviousAndNext" Grid.Row="2" Background="Cyan" Height="5" HorizontalAlignment="Stretch"  />
        <TextBlock VerticalAlignment="Bottom" Grid.Row="3" TextWrapping="Wrap">LOL<LineBreak/>LOL<LineBreak/>LOL</TextBlock>
    </Grid>
</Page>

機能する例は、最後の行 Height="Auto" を削除し、 * のように変更することです

ただし、これにより、最後の行のサイズが、要求されたセルのサイズではなく、その前の行と等しくなります。

4

2 に答える 2

3

GridSplitter独自の行または列に配置する必要があります。GridSplitter.ResizeDirectionおよびGridSplitter.ResizeBehaviorプロパティを試してください。

以下の記事をご覧ください。

アップデート

「スター係数」をGridLengthオブジェクトに提供することができます。例えば:

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:sys="clr-namespace:System;assembly=mscorlib" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">   
    <Grid ShowGridLines="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="95*" MinHeight="20" /> <!--here we are using 95*-->
            <RowDefinition Height="Auto" />
            <RowDefinition Height="5*" MinHeight="30"/> <!--and here we are using 5*-->     
        </Grid.RowDefinitions>
        <TextBlock Grid.Row="0" Text="Foo" />
        <TextBlock Grid.Row="1" Text="Bar" />
        <GridSplitter ResizeDirection="Rows"  Grid.Row="2" Background="Cyan" Height="5" HorizontalAlignment="Stretch"  />
        <TextBlock VerticalAlignment="Bottom" Grid.Row="3" TextWrapping="Wrap">LOL<LineBreak/>LOL<LineBreak/>LOL</TextBlock>
    </Grid> 
</Page>

GridSplitterそのため、不明確な動作なしで必要なレイアウトが用意されています。

于 2010-09-30T07:39:58.067 に答える
1

ドラット、私を打ち負かしてください。私が持っているものを投稿することもできます。あなたの問題は、3行目の定義にあります。上にスクロールし始めてテキストが消えると、行の高さが増え続けます。Eugene の解決策が機能しない場合は、最大の高さを何らかの制限に設定してみてください。

于 2010-09-30T07:55:48.777 に答える