如何在WPF

时间:2019-05-16 08:51:10

标签: wpf

enter image description here如何在WPF中在数据网格的最后一行设置滚动条

                        <ScrollViewer>
                            <DataGrid Grid.Row="0"  ItemsSource="{Binding   CM.SupportMessagesList}" CanUserAddRows="False" AutoGenerateColumns="False"  HorizontalGridLinesBrush="Transparent" VerticalGridLinesBrush="Transparent"  IsReadOnly="True" Background="White" AreRowDetailsFrozen="True" RowHeaderWidth="0" ColumnHeaderHeight="0"  x:Name="SupportMessagesGrid"  >
                            <DataGrid.Columns>

                            </DataGrid.Columns>
                            </DataGrid>
                        </ScrollViewer>

滚动条默认显示在数据网格的最后一行,并且显示最后一行

1 个答案:

答案 0 :(得分:2)

                 <!-- SizeChanged event is create in DataGrid -->

                   <ScrollViewer  x:Name="MessageScrollbar" CanContentScroll="False">

                      <DataGrid SizeChanged="SupportMessagesGrid_SizeChanged"></DataGrid>

                    </ScrollViewer>

                    <!--Code-->

                   private void SupportMessagesGrid_SizeChanged(object sender, SizeChangedEventArgs e)

                   {

                         MessageScrollbar.ScrollToVerticalOffset(e.NewSize.Height + 50); 

                        //We got actual height of DataGrid  using  e.NewSize.Height

                   }