Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
145670 | Jul 3,2019 06:51 AM UTC | Jul 9,2019 01:56 PM UTC | WPF | 3 |
![]() |
Tags: SfDataGrid |
public class CustomBehavior : Behavior<SfDataGrid>
{
protected override void OnAttached()
{
this.AssociatedObject.Loaded += AssociatedObject_Loaded;
this.AssociatedObject.CurrentCellActivating += AssociatedObject_CurrentCellActivating;
}
private void AssociatedObject_CurrentCellActivating(object sender, CurrentCellActivatingEventArgs e)
{
var rowIndex = e.CurrentRowColumnIndex.RowIndex;
var dataRow = AssociatedObject.RowGenerator.Items.FirstOrDefault(row => row.RowIndex == rowIndex) as DataRow;
//you can write your own code here.
}
private void AssociatedObject_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
this.AssociatedObject.View.Records.CollectionChanged += Records_CollectionChanged;
}
private void Records_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
var rowIndex =this.AssociatedObject.ResolveToRowIndex(e.NewItems[0]);
this.AssociatedObject.ScrollInView(new RowColumnIndex(rowIndex,this.AssociatedObject.GetFirstColumnIndex()));
AssociatedObject.Dispatcher.BeginInvoke(DispatcherPriority.Background,
new Action(() =>
{
var dataRow = AssociatedObject.RowGenerator.Items.FirstOrDefault(row => row.RowIndex == rowIndex) as DataRow;
//you can write your own code here.
}));
}
}
} |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.