我没有使用DataGrid或ListView,而是使用ScrollViewer和Grids来创建包含每个单元格列的项目包装面板的单元格.
我想要一个与datagrid或listview的标题列类似的行为,以便在垂直滚动它下面的项目时保持冻结,但让它水平滚动.
我目前有以下作为我的主窗口的根目录,除了当显示垂直滚动条时,项目的对齐关闭.
笔记:
因此,当"innerScrollViewer"显示其垂直滚动条时,项目不再与外部列标题对齐,并且由于右侧垂直滚动条,项目将向左移动.如何在显示垂直滚动条的两种情况下使用外部列标题动态排列内容?
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
<Grid x:Name="mainGrid"
Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ScrollViewer}}, Path=ViewportWidth}">
<RowDefinitions>
<RowDefinition Height="Auto" /> <!-- Contains Header columns dynamically added to be "frozen" -->
<RowDefinition Height="*" /> <!-- "row groupings" -->
</RowDefinitions>
<ScrollViewer x:Name="innerScrollViewer"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
Grid.Row="1"
Grid.ColumnSpan="{Binding Path=NumColumns}">
<ItemsControl Name="mainWorkItemsItemsControl"
Width="{Binding ActualWidth, ElementName=mainGrid}"
ItemsSource="{Binding MyGroups}"
ItemTemplate="{StaticResource groupedTemplate}" />
</ScrollViewer>
</Grid>
</ScrollViewer>
<DataTemplate x:Key="groupedTemplate">
<ItemsControl ItemsSource="{Binding GroupItems}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<!-- Creates a grid with one row and the same number of …Run Code Online (Sandbox Code Playgroud)