【发布时间】:2011-02-22 10:25:27
【问题描述】:
我需要连续滚动 DataGrid,所以它会每秒移动到下一行(例如),并在到达 end 时移动到第一项。请建议完成这项任务的最佳方法。
【问题讨论】:
标签: silverlight
我需要连续滚动 DataGrid,所以它会每秒移动到下一行(例如),并在到达 end 时移动到第一项。请建议完成这项任务的最佳方法。
【问题讨论】:
标签: silverlight
您可以使用 Dispatcher 并每秒计算所选索引。 像这样的:
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]);
}
编辑
选择的索引在这里后面的代码中设置,你也可以绑定它并在选择更改处理程序中做 ScrollIntoView 的东西。
BR,
TJ
【讨论】: