6

gridsplitter を使用してグリッドのサイズを変更すると、行は * 他の行が折りたたまれているときにスペースを再利用しません。

3 行のマスター詳細ビューに次のグリッドがあります。中央のスプリッターの上にあるデータ グリッドと、最後の行のコンテンツ コントロール ビュー。スプリッターには、詳細を折りたたむための閉じるボタンがあります。これはすべて、ユーザーがグリッドスプリッターを使用してサイズを変更すると例外があります。

    <Grid Margin="3,0">
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Style="{StaticResource CollapsableRow}"/><!-- Splitter Here -->
        <RowDefinition Style="{StaticResource CollapsableRow}"/>
    </Grid.RowDefinitions>

GridSplitter スタイル:

    <Style x:Key="gridSplitterStyle" TargetType="{x:Type GridSplitter}">
    <Setter Property="Visibility" Value="{Binding IsItemSelected, Converter={StaticResource BoolToShow},ConverterParameter='Visible|Collapsed'}" />
    <Setter Property="Width" Value="Auto"/>
    <Setter Property="Height" Value="14"/>
    <Setter Property="HorizontalAlignment" Value="Stretch"/>
    <Setter Property="Border.BorderBrush" Value="#FF6593CF" />
    <Setter Property="Border.BorderThickness" Value="0,1,0,0" />
    <Setter Property="UIElement.SnapsToDevicePixels" Value="True" />
    <Setter Property="UIElement.Focusable" Value="False" />
    <Setter Property="Control.Padding" Value="7,7,7,7" />
    <Setter Property="Cursor" Value="SizeNS" /></Style>

私が言ったように、グリッドスプリッターを使用してサイズを変更しない限り、折りたたみは正しく機能します。その後、空白は残ります。

編集: HB と codenaked にはシンプルで一貫した提案があったので、データトリガーで成功せずにそれらを実装しようとしました:

<Style x:Key="CollapsableRow" TargetType="{x:Type RowDefinition}">
    <Style.Triggers>
        <DataTrigger Binding="{Binding SelectedItem, Converter={StaticResource IsNullConverter}}" Value="True">
            <Setter Property="RowDefinition.Height" Value="0"/>
        </DataTrigger>
        <DataTrigger Binding="{Binding SelectedItem, Converter={StaticResource IsNullConverter}}" Value="False">
            <Setter Property="RowDefinition.Height" Value="Auto"/>
        </DataTrigger>            
    </Style.Triggers>
</Style>   
4

4 に答える 4

7

グリッド スプリッターと詳細は既に非表示になっているため、次の行定義の高さをリセットするために可視性を選択することは明らかでした。

 /// <summary>
/// Grid splitter that show or hides the following row when the visibility of the splitter is changed. 
/// </summary>
public class HidableGridSplitter : GridSplitter { 

    GridLength height;

    public HidableGridSplitter()
    {
        this.IsVisibleChanged += HideableGridSplitter_IsVisibleChanged;
        this.Initialized += HideableGridSplitter_Initialized;
    }

    void HideableGridSplitter_Initialized(object sender, EventArgs e)
    {
        //Cache the initial RowDefinition height,
        //so it is not always assumed to be "Auto"
        Grid parent = base.Parent as Grid;
        if (parent == null) return;
        int rowIndex = Grid.GetRow(this);
        if (rowIndex + 1 >= parent.RowDefinitions.Count) return;
        var lastRow = parent.RowDefinitions[rowIndex + 1];
        height = lastRow.Height;
    }

    void HideableGridSplitter_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
    {
        Grid parent = base.Parent as Grid;
        if (parent == null) return;

        int rowIndex = Grid.GetRow(this);

        if (rowIndex + 1 >= parent.RowDefinitions.Count) return;

        var lastRow = parent.RowDefinitions[rowIndex + 1];

        if (this.Visibility == Visibility.Visible)
        {
            lastRow.Height = height;
        }
        else
        {
            height = lastRow.Height; 
            lastRow.Height = new GridLength(0);
        }

    }
于 2011-05-12T10:04:16.497 に答える
3

アニメーションを使用して、グリッドスプリッターによる行/列定義のオーバーライドを解決できます。GridSplitter overrides ColumnDefinition's style trigger?で同様の質問に対する私の回答を参照してください。

于 2012-11-16T09:22:58.287 に答える
1

GridSplitter を使用すると、Heights はもはやAuto具体的な値になります。スタイルまたはイベントとコード ビハインドを使用して値を手動で元に戻す必要があります。たとえば、これにより、ダブルクリック時に自動サイズ変更された列がリセットされます。

private void ColumnSplitter_DoubleClick(object sender, MouseButtonEventArgs e)
{
    if (!ColumnTreeView.Width.IsAuto) ColumnTreeView.Width = new GridLength();
}
于 2011-05-10T19:22:10.777 に答える
0

指定した内容に基づいて、GridSplitter は前後の行のサイズを変更します。次のコードを使用して、これを実際に確認できます。

<Grid Margin="3,0">
    <Grid.RowDefinitions>
        <RowDefinition x:Name="row0" Height="*" />
        <RowDefinition Height="Auto" />
        <RowDefinition x:Name="row2" Height="Auto" />
    </Grid.RowDefinitions>
    <Border Background="Red" >
        <TextBlock Text="{Binding ElementName=row0, Path=Height}" HorizontalAlignment="Center" VerticalAlignment="Center" />
    </Border>
    <GridSplitter Grid.Row="1" Style="{StaticResource gridSplitterStyle}" HorizontalAlignment="Stretch" />
    <Border Background="Blue" Grid.Row="2" MinHeight="50">
        <TextBlock Text="{Binding ElementName=row2, Path=Height}" HorizontalAlignment="Center" VerticalAlignment="Center" />
    </Border>
</Grid>

最後の行のサイズは、実際には Auto から固定の高さに変更されます。したがって、その行のコンテンツを折りたたんでも、指定されたスペースを占有します。行をリセットして、そのHeight="Auto"内容で本当に折りたたむ必要があります。

于 2011-05-10T19:24:37.387 に答える