WPF с использованием GridSplitter для отдельного столбца строки в сетке

Я хочу иметь GridSplitter, который изменяет размер только одной ячейки (на самом деле неправильный термин сам по себе для сетки WPF, давайте назовем ее отдельной сеткой [r] [c]), и ячейку, прилегающую к ней, для изменения размера.

Вот что я пробовал:

<Grid>
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>

            <ColumnDefinition></ColumnDefinition>

            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Border Grid.IsSharedSizeScope="True"  Margin="2" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Row="0" Grid.Column="0">
            <TextBlock>Testing 1</TextBlock>
        </Border>
        <Border Grid.IsSharedSizeScope="True"  Margin="2" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Row="0" Grid.Column="1">
            <TextBlock>Testing 2</TextBlock> </Border>
        <Border Grid.IsSharedSizeScope="True"  Margin="2" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Row="0" Grid.Column="2">
            <TextBlock>Testing 2</TextBlock>
        </Border>
        <Border Grid.IsSharedSizeScope="True" Margin="2" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Row="1" Grid.Column="0">
            <TextBlock>Testing 3</TextBlock>
        </Border>
        <Border Grid.IsSharedSizeScope="True"  Margin="2" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Row="1" Grid.Column="1">
            <TextBlock>Testing 4</TextBlock></Border>
        <Border Grid.IsSharedSizeScope="True"  Margin="2" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Row="1" Grid.Column="2">
            <TextBlock>Testing 5</TextBlock></Border>
        <Border Grid.IsSharedSizeScope="True"  Margin="2" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Row="3" Grid.Column="0">
            <TextBlock>Testing 6</TextBlock></Border>
        <Border Grid.IsSharedSizeScope="True"  Margin="2" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Row="3" Grid.Column="1">
            <TextBlock>Testing 7</TextBlock></Border>
        <Border Grid.IsSharedSizeScope="True"  Margin="2" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Row="3" Grid.Column="2">
            <TextBlock>Testing 8</TextBlock></Border>
        <GridSplitter Grid.Row="0"
                      Grid.Column="1"
                      Margin="1"
                      ResizeBehavior="PreviousAndCurrent"
                      HorizontalAlignment="Left" 
                        VerticalAlignment="Stretch"
                        Background="Black" 
                        ShowsPreview="true"
                        ResizeDirection="Columns"
                        Width="2"/>
        <GridSplitter Grid.Row="1"
                      Grid.Column="1"
                      Margin="1"
                      ResizeBehavior="PreviousAndCurrent"
                      HorizontalAlignment="Left" 
                        VerticalAlignment="Stretch"
                        Background="Black" 
                        ShowsPreview="true"
                        ResizeDirection="Columns"
                        Width="2"/>
        <GridSplitter Grid.Row="2" 
                      Grid.Column="1"
                      Margin="1"
                      ResizeBehavior="PreviousAndCurrent"
                      HorizontalAlignment="Left" 
                        VerticalAlignment="Stretch"
                        Background="Black" 
                        ShowsPreview="true"
                        ResizeDirection="Columns"
                        Width="2"/>
        <GridSplitter Grid.Row="2" 
                      Grid.Column="1"
                      Margin="1"
                      ResizeBehavior="PreviousAndCurrent"

                      HorizontalAlignment="Stretch" 
                        VerticalAlignment="Top"
                        Background="Black" 
                        ShowsPreview="true"
                        ResizeDirection="Columns"
                        Width="2"/>
        <GridSplitter Grid.Row="0" 
                      Grid.Column="2"
                      Margin="1"
                      ResizeBehavior="PreviousAndCurrent"
                      HorizontalAlignment="Left" 

                      VerticalAlignment="Stretch"
                        Background="Black" 
                        ShowsPreview="true"
                        ResizeDirection="Columns"
                        Width="2"/>
        <GridSplitter Grid.Row="1" 
                      Grid.Column="2"
                      Margin="1"
                      ResizeBehavior="PreviousAndCurrent"
                      HorizontalAlignment="Left" 
                        VerticalAlignment="Stretch"
                        Background="Black" 
                        ShowsPreview="true"
                        ResizeDirection="Columns"
                        Width="2"/>
        <GridSplitter Grid.Row="2" 
                      Grid.Column="2"
                      Margin="1"
                      ResizeBehavior="PreviousAndCurrent"
                      HorizontalAlignment="Left" 
                        VerticalAlignment="Stretch"
                        Background="Black" 
                        ShowsPreview="true"
                        ResizeDirection="Columns"
                        Width="2"/>
        <GridSplitter Grid.Row="1"
                      Grid.Column="0"
                      Margin="1"
                      ResizeBehavior="PreviousAndCurrent"
                      HorizontalAlignment="Stretch" 
                        VerticalAlignment="Top"
                        Background="Black" 
                        ShowsPreview="true"
                        ResizeDirection="Rows"
                        Height="2"/>
        <GridSplitter Grid.Row="2"
                      Grid.Column="0"
                      Margin="1"
                      ResizeBehavior="PreviousAndCurrent"
                      HorizontalAlignment="Stretch" 
                        VerticalAlignment="Top"
                        Background="Black" 
                        ShowsPreview="true"
                        ResizeDirection="Rows"
                        Height="2"/>
        <GridSplitter Grid.Row="1" 
                      Grid.Column="1"
                      Margin="1"
                      ResizeBehavior="PreviousAndCurrent"
                      HorizontalAlignment="Stretch" 
                        VerticalAlignment="Top"
                        Background="Black" 
                        ShowsPreview="true"
                        ResizeDirection="Rows"
                        Height="2"/>
        <GridSplitter Grid.Row="2" 
                      Grid.Column="1"
                      Margin="1"
                      ResizeBehavior="PreviousAndCurrent"
                      HorizontalAlignment="Stretch" 
                        VerticalAlignment="Top"
                        Background="Black" 
                        ShowsPreview="true"
                        ResizeDirection="Rows"
                        Height="2"/>
        <GridSplitter Grid.Row="1" 
                      Grid.Column="2"
                      Margin="1"
                      ResizeBehavior="PreviousAndCurrent"
                      HorizontalAlignment="Stretch" 
                        VerticalAlignment="Top"
                        Background="Black" 
                        ShowsPreview="true"
                        ResizeDirection="Rows"
                        Height="2"/>
        <GridSplitter Grid.Row="2" 
                      Grid.Column="2"
                      Margin="1"
                      ResizeBehavior="PreviousAndCurrent"
                      HorizontalAlignment="Stretch" 
                        VerticalAlignment="Top"
                        Background="Black" 
                        ShowsPreview="true"
                        ResizeDirection="Rows"
                        Height="2"/>
    </Grid>

Я хочу, чтобы он вел себя так, чтобы размер отдельной ячейки в сетке изменялся.

  1. При запуске приложения

Вот что выглядит при запуске приложения

  1. При изменении размера с помощью разделителя сетки:

При изменении размера

  1. После изменения размера:

После изменения размера

Я хотел, чтобы размеры Only Grid[ 0][0] и Grid[0][1] изменялись


person Bhanu Chhabra    schedule 17.04.2017    source источник


Ответы (1)


У вас есть 3 столбца и 3 строки, а не 3 столбца внутри каждой строки, попробуйте следующее:

<Grid  >
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <Grid Grid.Row="0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <GridSplitter Grid.Column="0"/>
        <GridSplitter Grid.Column="1"/>
        <GridSplitter Grid.Column="2"/>
    </Grid>
    <Grid Grid.Row="1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

    </Grid>
    <Grid Grid.Row="2">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>   
    </Grid>
</Grid>
person Celso Lívero    schedule 17.04.2017
comment
Привет, спасибо за предложение ... И мне очень жаль, что я недостаточно ясно выразился. Ваше решение сработало, но только для столбцов, а не для строк :( - person Bhanu Chhabra; 17.04.2017