我有一个ItemsControl
,它通过数据绑定到一个ObservableCollection
。我在代码后台中有这个方法,它将一个新的模型添加到列表中。我希望将新的项目(在列表底部)滚动到视图中。
我认为当我查询大小时,ItemsControl
的大小还没有更新,因为添加模型之前和之后的ActualHeight
是相同的。这段代码的效果是滚动到新项目上方略微的位置。
我如何知道新的ActualHeight
将是多少?
以下是我的代码:
ViewModel.CreateNewChapter();
var height = DocumentElements.ActualHeight;
var width = DocumentElements.ActualWidth;
DocumentElements.BringIntoView(new Rect(0, height - 1, width, 1));