有谁知道如何将 TreeItem 滚动到所选项目。我一直在谷歌搜索,但不清楚的结果对我有用。我尝试了 BringIntoView() 但它不起作用......
问问题
980 次
1 回答
0
一个简单的解决方案是使用绑定到选定项的行为,请参阅: Data binding to SelectedItem in a WPF Treeview。将 OnSelectedItemPropertyChanged 修改为:
private static void OnSelectedItemPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
((BindableSelectedItemBehavior) sender).OnSelectedItemChanged(e.NewValue);
}
private void OnSelectedItemChanged(object newValue)
{
var treeViewItem = AssociatedObject.ItemContainerGenerator.ContainerFromItem(newValue) as TreeViewItem;
treeViewItem.SetValue(TreeViewItem.IsSelectedProperty, true);
treeViewItem.BringIntoView();
}
于 2012-09-20T11:31:54.187 回答