如何自动滚动的DataGrid的WPF [英] How to autoscroll on WPF datagrid
问题描述
我觉得我很笨。现在我搜索了15分钟,发现了几个不同的解决方案,用于滚动的数据网格,但没有似乎为我工作。
I think I am stupid. I searched now for 15 minutes, and found several different solutions for scrolling on datagrids, but none seems to work for me.
我使用WPF在.NET 3.5和WPF工具包DataGrid中。当我的观察集合的变化,完美的作品我的网格得到更新。现在,我的DataGrid位于正常的网格内,如果DataGrid变得太大滚动条出现。还精...
I am using WPF with .NET 3.5 and the WPF Toolkit DataGrid. My grid gets updated when my observable collection changes, works perfectly. Now, my DataGrid is located inside a normal Grid and scrollbars appear if the DataGrid gets too big. Also fine...
和现在来的1,000,000 $问题:
And now comes the 1.000.000 $ question:
我如何将DataGrid滚动到最后一排?
有:
How do I get the datagrid to scroll to the last row? There is:
- 没有AutoScroll属性
- 没有CurrentRowSelected指数
- 一个CurrentCell,但没有收藏我可以用CurrentCell = AllCells.Last
任何想法?我觉得自己真的很愚蠢,它似乎很奇怪,这问题太难。我缺少什么?
Any ideas? I feel really stupid, and it seems strange that this question is so hard. What am I missing?
推荐答案
)
if (mainDataGrid.Items.Count > 0)
{
var border = VisualTreeHelper.GetChild(mainDataGrid, 0) as Decorator;
if (border != null)
{
var scroll = border.Child as ScrollViewer;
if (scroll != null) scroll.ScrollToEnd();
}
}
这篇关于如何自动滚动的DataGrid的WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!