I have a requirement to freeze the right-hand column in a grid when scrolling. Elsewhere, I am using the SelectiveScrollingGrid to freeze the left-hand column just fine, but when the frozen column is right-hand it no longer works.
我需要在滚动时冻结网格中的右侧列。在其他地方,我使用SelectiveScrollingGrid来冻结左侧列,但是当冻结的列是右侧时它不再有效。
Here is some XAML:
这是一些XAML:
<!-- Right aligned frozen column results in clipping when scrollbar appears -->
<SelectiveScrollingGrid>
<SelectiveScrollingGrid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</SelectiveScrollingGrid.ColumnDefinitions>
<DataGridCellsPresenter Grid.Column="0" ItemsPanel="{TemplateBinding ItemsPanel}" />
<DataGridRowHeader Grid.Column="1"
SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical">
</SelectiveScrollingGrid>
The above does not work (when you resize a window containing a grid the DataGridRowHeader area becomes clipped when the scrollbar appears).
以上操作无效(当您调整包含网格的窗口大小时,当滚动条出现时,DataGridRowHeader区域将被剪裁)。
The below XAML works just fine however:
下面的XAML工作得很好但是:
<!-- Left aligned frozen column works! -->
<SelectiveScrollingGrid>
<SelectiveScrollingGrid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</SelectiveScrollingGrid.ColumnDefinitions>
<DataGridCellsPresenter Grid.Column="1" ItemsPanel="{TemplateBinding ItemsPanel}" />
<DataGridRowHeader Grid.Column="0"
SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical">
</SelectiveScrollingGrid>
Can SelectiveScrollingGrid be used with a frozen column on the right? If not is there another solution?
SelectiveScrollingGrid可以与右侧的冻结列一起使用吗?如果没有另外的解决方案?
1 个解决方案
#1
0
you can freeze any column you like, other columns would scroll pass/float underneath the frozen columns, in below snippet the text block in the first column is only allowed to scroll vertically ( horizontal scroll will have no effect on this text block)
你可以冻结你喜欢的任何列,其他列将在冻结列下滚动传递/浮动,在下面的代码段中,第一列中的文本块只允许垂直滚动(水平滚动对此文本块没有影响)
<SelectiveScrollingGrid>
<SelectiveScrollingGrid.ColumnDefinitions>
<ColumnDefinition Width="{Binding ElementName=XX,Path=ActualWidth}" ></ColumnDefinition>
<ColumnDefinition Width="{Binding ElementName=LastName,Path=ActualWidth}"></ColumnDefinition>
<ColumnDefinition Width="{Binding ElementName=Address,Path=ActualWidth}"></ColumnDefinition>
</SelectiveScrollingGrid.ColumnDefinitions>
<TextBlock Text="1111111111111" Grid.Column="0" SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical" ></TextBlock>
<TextBlock Text="2" Grid.Column="1"></TextBlock>
<TextBlock Text="3" Grid.Column="2"></TextBlock>
</SelectiveScrollingGrid>
#1
0
you can freeze any column you like, other columns would scroll pass/float underneath the frozen columns, in below snippet the text block in the first column is only allowed to scroll vertically ( horizontal scroll will have no effect on this text block)
你可以冻结你喜欢的任何列,其他列将在冻结列下滚动传递/浮动,在下面的代码段中,第一列中的文本块只允许垂直滚动(水平滚动对此文本块没有影响)
<SelectiveScrollingGrid>
<SelectiveScrollingGrid.ColumnDefinitions>
<ColumnDefinition Width="{Binding ElementName=XX,Path=ActualWidth}" ></ColumnDefinition>
<ColumnDefinition Width="{Binding ElementName=LastName,Path=ActualWidth}"></ColumnDefinition>
<ColumnDefinition Width="{Binding ElementName=Address,Path=ActualWidth}"></ColumnDefinition>
</SelectiveScrollingGrid.ColumnDefinitions>
<TextBlock Text="1111111111111" Grid.Column="0" SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical" ></TextBlock>
<TextBlock Text="2" Grid.Column="1"></TextBlock>
<TextBlock Text="3" Grid.Column="2"></TextBlock>
</SelectiveScrollingGrid>