Telerik for UWP RadDataGrid - 添加项目时滚动到底部
Telerik for UWP RadDataGrid - Scroll to bottom when item is added
我正在尝试让 RadDataGrid (UWP) 在添加新项目时自动滚动到底部。我已经看过以下内容:
第二个是关闭的,但它没有提到更新 ItemsSource 时要绑定到的事件。
我在 Raspberry PI.
上用 Windows 10 IoT 在 c# 中使用它
有没有简单的方法让它自动滚动?
我使用 ObservableCollection
对象作为 RadDataGrid 的 ItemsSource。然后,我注册 CollectionChanged 事件来检测 ItemsSource 是否更新。在事件处理程序中,您可以调用 DataGrid.ScrollIndexIntoView
方法滚动到底部。
请参阅我的以下代码示例以供参考:
<telerikGrid:RadDataGrid x:Name="DataGrid"/>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
list = new ObservableCollection<Data>{
new Data { Country = "India", Capital = "New Delhi"},
new Data { Country = "South Africa", Capital = "Cape Town"},
new Data { Country = "Nigeria", Capital = "Abuja" },
new Data { Country = "Singapore", Capital = "Singapore" },
new Data { Country = "India", Capital = "New Delhi"}
};
list.CollectionChanged += List_CollectionChanged;
DataGrid.ItemsSource = list;
}
private void List_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
{
DataGrid.ScrollIndexIntoView(list.Count - 1);
}
}
public ObservableCollection<Data> list { get; set; }
}
public class Data
{
public string Country { get; set; }
public string Capital { get; set; }
}
我正在尝试让 RadDataGrid (UWP) 在添加新项目时自动滚动到底部。我已经看过以下内容:
第二个是关闭的,但它没有提到更新 ItemsSource 时要绑定到的事件。
我在 Raspberry PI.
上用 Windows 10 IoT 在 c# 中使用它有没有简单的方法让它自动滚动?
我使用 ObservableCollection
对象作为 RadDataGrid 的 ItemsSource。然后,我注册 CollectionChanged 事件来检测 ItemsSource 是否更新。在事件处理程序中,您可以调用 DataGrid.ScrollIndexIntoView
方法滚动到底部。
请参阅我的以下代码示例以供参考:
<telerikGrid:RadDataGrid x:Name="DataGrid"/>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
list = new ObservableCollection<Data>{
new Data { Country = "India", Capital = "New Delhi"},
new Data { Country = "South Africa", Capital = "Cape Town"},
new Data { Country = "Nigeria", Capital = "Abuja" },
new Data { Country = "Singapore", Capital = "Singapore" },
new Data { Country = "India", Capital = "New Delhi"}
};
list.CollectionChanged += List_CollectionChanged;
DataGrid.ItemsSource = list;
}
private void List_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
{
DataGrid.ScrollIndexIntoView(list.Count - 1);
}
}
public ObservableCollection<Data> list { get; set; }
}
public class Data
{
public string Country { get; set; }
public string Capital { get; set; }
}