首页 > 解决方案 > 如何设置 GridSplitter 对网格的喜爱

问题描述

我在 UWP 中使用 microsoft 工具包并有类似的东西

<Grid>
   <Grid.RowDefinitions>
        <RowDefinition Height="7*"/>
        <RowDefinition Height="3"/>
        <RowDefinition Height="3*"/>                    
        <RowDefinition Height="4*"/>
   </Grid.RowDefinitions>
<Grid Grid.Row="0">
  <Grid.ColumnDefinitions>
      <ColumnDefinition Width="2*"/>
      <ColumnDefinition Width="3*"/>
  </Grid.ColumnDefinitions>  
</Grid>
<Grid Grid.Row="1">
<controls:GridSplitter ResizeBehavior="PreviousAndNext" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
</Grid>
</Grid>

我怎样才能将拆分器的感情设置为仅列 1 的人?我不想像第 1 列那样调整第 0 列的大小。就像在图像中一样,当我使用拆分器时,我只希望拆分器调整第 1 列的大小,第 0 列只是冻结。

像这样的分离器

新代码:

<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
            <Grid.RowDefinitions>
                <RowDefinition Height="7*"/>
                <RowDefinition Height="3"/>
                <RowDefinition Height="3*"/>
                <RowDefinition Height="4*"/>
            </Grid.RowDefinitions>
            <Grid Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="2*"/>
                    <ColumnDefinition Width="3*"/>                   
                </Grid.ColumnDefinitions>
                <Grid Grid.Column="0" Background="Red"></Grid>
            </Grid>
            <Grid Grid.Row="1">
                <controls:GridSplitter GripperCursor="Help" HorizontalAlignment="Stretch" Grid.Column="1" ResizeDirection="Columns"
                                       ResizeBehavior="CurrentAndNext" CursorBehavior="ChangeOnSplitterHover" VerticalAlignment="Stretch" ></controls:GridSplitter>
            </Grid>
            <Grid Grid.Row="2">
                <TextBlock Text="aoisdjaisodjaiosdjsa" Width="60" Height="60" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
            </Grid>
</Grid>

标签: c#uwpgridsplitter

解决方案


你有不止一个Grid,所以我不知道你想要什么网格,GridSplitter但你所要做的就是创建一个你想要将控件放入的GridSplitter属性。Grid.Column

例子:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="7*"/>
        <RowDefinition Height="3"/>
        <RowDefinition Height="3*"/>
        <RowDefinition Height="4*"/>
    </Grid.RowDefinitions>
    <Grid Grid.Row="0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="2*"/>
            <ColumnDefinition Width="3*"/>
        </Grid.ColumnDefinitions>
    </Grid>
    <!-- Means GridSplitter stay on column 1 based on the grid he is -->
    <controls:GridSplitter Grid.Column="1" ResizeBehavior="PreviousAndNext" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
    <Grid Grid.Row="1">
       <!-- Your XAML code here-->
    </Grid>
</Grid>

Grid.RowSpan如果您必须跨越所有行,则可以使用。


推荐阅读