I have got the Scrolling to work by using the DataContextChanged event and the CollectionChanged event - but this is a very complex and ugly Code for such a simple Problem.
Do you have a nice solution for this?
Thanks Kurt
private void Button_Click(object sender, RoutedEventArgs e)
{
(this.DataContext as ViewModel).OrdersDetails.Add(new OrderInfo() { CustomerID = "100009", Freight = 100 });
this.dataGrid.GetVisualContainer().ScrollOwner.ScrollToEnd();
Dispatcher.Invoke(new Action(() =>
{
var viewModel = this.dataGrid.DataContext as ViewModel;
//find the RowIndex for particular record
var RowIndex = this.dataGrid.ResolveToRowIndex(viewModel.OrdersDetails[viewModel.OrdersDetails.Count - 1]);
// CurrentCell is set if MappingName is EmployeeID
this.dataGrid.MoveCurrentCell(new RowColumnIndex(RowIndex, 0));
this.dataGrid.SelectionController.CurrentCellManager.BeginEdit();
}),System.Windows.Threading.DispatcherPriority.ApplicationIdle);
} |
model.Medications.CollectionChanged += (s, e1) =>
{
if (e1.Action == NotifyCollectionChangedAction.Add)
{
this.DataGrid.GetVisualContainer().ScrollOwner.ScrollToEnd();
...
Hi,
Although it is a ticket from 2016 it was holding the answer about how I can automatically scroll to the end of the datagrid.
So it is very useful to have this information available!
Thanks!
Ruud