我正在滚动整个Datagrid,包括标题,如下所示。然而,我无法找到一种方法来保持列标题旁边的滚动,让他们固定。如何到达?
<Grid Name="rowRecs0" Grid.Row="0">
<ScrollViewer Height="200" VerticalScrollBarVisibility="Auto">
<StackPanel>
<DataGrid
x:Name="datagridRecipes"
VerticalAlignment="Top"
AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserReorderColumns="False"
CanUserResizeColumns="False"
CanUserResizeRows="False"
CanUserSortColumns="False"
IsReadOnly="True"
ItemsSource="{Binding UsersItems}"
SelectedIndex="{Binding UserSelectedIndex}"
SelectedItem="{Binding UserSelectedItem}"
SelectionChanged="datagridRecipes_SelectionChanged">
<DataGrid.Columns>
<materialDesign:DataGridTextColumn
Width="*"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}"
Header="NAME">
<materialDesign:DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Height" Value="30" />
</Style>
</materialDesign:DataGridTextColumn.ElementStyle>
<materialDesign:DataGridTextColumn.Binding>
<Binding Path="RecipeName" />
</materialDesign:DataGridTextColumn.Binding>
</materialDesign:DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</StackPanel>
</ScrollViewer>
</Grid>
1条答案
按热度按时间k97glaaz1#
DataGrid已经有了内置的行滚动功能,它不会影响列标题(也不会影响行标题)。你只需要从你的布局XAML中删除你的Grid,ScrollViewer和StackPanel。在那之后,一切都将按照它应该的那样工作。
已更正布局的XAML: