Silverlight 如何连续滚动数据网格?
我需要连续滚动DataGrid,这样它将每秒移动到下一行(例如),并在到达结束时移动到第一项。请建议执行此任务的最佳方法。您可以使用调度程序,每秒钟计算所选索引。 大概是这样的:Silverlight 如何连续滚动数据网格?,silverlight,Silverlight,我需要连续滚动DataGrid,这样它将每秒移动到下一行(例如),并在到达结束时移动到第一项。请建议执行此任务的最佳方法。您可以使用调度程序,每秒钟计算所选索引。 大概是这样的: private int selectedIndex; public int SelectedIndex { get { return selectedIndex; } set
private int selectedIndex;
public int SelectedIndex
{
get { return selectedIndex; }
set
{
selectedIndex = value;
NotifyPropertyChanged("SelectedIndex");
}
}
private void BuildDispatcher()
{
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Interval = TimeSpan.FromSeconds(1);
dispatcherTimer.Tick += DispatcherTimerTick;
dispatcherTimer.Start();
}
void DispatcherTimerTick(object sender, EventArgs e)
{
if((SelectedIndex + 1) > MyCollection.Count)
{
SelectedIndex = 0;
}else
{
SelectedIndex++;
}
//EDIT!
MyDataGrid.SelectedIndex = SelectedIndex;
MyDataGrid.ScrollIntoView(MyDataGrid.SelectedItem, MyDataGrid.Columns[0]);
}
编辑
所选索引是在这里的代码隐藏中设置的,您还可以绑定它并在selection changed处理程序中执行ScrollIntoView操作
比尔
TJ它不起作用。选择项更改,但网格不会滚动。您好,您好。请参阅我的编辑。您需要添加ScrollIntoView来完成它。MyDataGrid是保存数据的网格。如果要绑定它,可以处理selection changed事件,然后使用ScrollIntoView。这是否解决了您的问题?无论如何,这是一个糟糕的解决方案:)在所选项目到达第一页的末尾之前,会有一个很大的延迟,然后才开始滚动。