SL 4:ScrollViewer - RequestBringIntoView

发布于 2024-12-31 21:12:01 字数 1628 浏览 4 评论 0原文

如何在 ScrollViewer 中找到处理 RequestBringIntoView 事件的组件?
它没有暴露在两个 ScrollBar 部分上(无论如何,不​​是直接暴露)。
感谢您的指点...

更新:相关:我可以获得 ScrollViewer 的 ScrollContentPresenter 部分吗?怎么办?
谢谢——

大局观:
我们有一个包含在 ScrollViewer 中的大画布。在运行时,任意数量的 UserControl(我将其称为“Blob”)会从数据库添加到画布中。它们的位置和内容来自数据库。用户可以通过单击某个斑点来“选择”该斑点,并且其外观会发生变化以表明它已被选中。
如果用户使用滚动条将选定的斑点移出视图,然后单击另一个斑点,则画布会滚动,以便先前不在视图中的斑点再次出现在视图中。我认为这是由于某些对象引发了 RequestBringIntoView,并且 ScrollViewer 正在处理它。
希望这是有道理的...

更多信息:
向 Scrollviewer 的滚动条 ValueChanged 事件添加了一个处理程序 (sb_ValueChanged)。这是通过鼠标单击引发滚动的堆栈:

OurControl.sb_ValueChanged() System.Windows.dll!System.Windows.Controls.Primitives.RangeBase.OnValueChanged() System.Windows.dll!System.Windows.Controls.Primitives.ScrollBar.OnValueChanged() System.Windows。 dll!System.Windows.Controls.Primitives.RangeBase.OnValuePropertyChanged() System.Windows.dll!System.Windows.DependencyObject.RaisePropertyChangeNotifications()
System.Windows.dll!System.Windows.DependencyObject.UpdateEffectiveValue() System.Windows.dll!System.Windows.DependencyObject.SetValueInternal() System.Windows.dll!System.Windows.DependencyObject.SetValue() System.Windows.dll!System.Windows.Controls.ScrollViewer.InvalidateScrollInfo() System.Windows.dll!System.Windows.Controls.ScrollContentPresenter.VerifyScrollData()
System.Windows.dll!System.Windows.Controls.ScrollContentPresenter.ArrangeOverride() System.Windows.dll!System.Windows.FrameworkElement.ArrangeOverride()

如果我能找出引发恶作剧的 FrameworkElement 实际上是什么......

How can I find the component in a ScrollViewer that handles the RequestBringIntoView event?
It isn't exposed on the two ScrollBar parts (not directly, anyway).
Thanks for any pointers...

UPDATE: Related: Can I get the ScrollContentPresenter part of the ScrollViewer? How?
Thanks --

Bigger picture:
We have a large Canvas contained in a ScrollViewer. At runtime, an arbitrary number of UserControls (I'll call them 'Blobs') are added to the canvas from the db. Their position and content come from the db. A user can 'select' a blob by clicking on it, and its appearance changes to indicate it is selected.
If the user uses a scrollbar to move the selected blob out of view, then clicks on another blob, the Canvas is scrolled so the previously-out-of-view blob is in view again. I assume this is due to some object raising the RequestBringIntoView, and the ScrollViewer is handling it.
Hope this makes sense...

Yet more info:
Added a handler (sb_ValueChanged) to the Scrollviewer's scrollbar ValueChanged event. Here's the stack from the mouse click that precipitates the scrolling:

OurControl.sb_ValueChanged() System.Windows.dll!System.Windows.Controls.Primitives.RangeBase.OnValueChanged() System.Windows.dll!System.Windows.Controls.Primitives.ScrollBar.OnValueChanged() System.Windows.dll!System.Windows.Controls.Primitives.RangeBase.OnValuePropertyChanged()
System.Windows.dll!System.Windows.DependencyObject.RaisePropertyChangeNotifications()
System.Windows.dll!System.Windows.DependencyObject.UpdateEffectiveValue()
System.Windows.dll!System.Windows.DependencyObject.SetValueInternal()
System.Windows.dll!System.Windows.DependencyObject.SetValue()
System.Windows.dll!System.Windows.Controls.ScrollViewer.InvalidateScrollInfo() System.Windows.dll!System.Windows.Controls.ScrollContentPresenter.VerifyScrollData()
System.Windows.dll!System.Windows.Controls.ScrollContentPresenter.ArrangeOverride()
System.Windows.dll!System.Windows.FrameworkElement.ArrangeOverride()

If only I could find out what the FrameworkElement that starts the mischief actually is...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

思念满溢 2025-01-07 21:12:01

抱歉...它似乎不像 WPF 中那样存在。 检查此链接 一个方便的解决方案。

更新:好的...为此,您可能需要遍历可视化树,并且需要完成某种递归搜索。但是,假设您使用滚动查看器的默认模板 如此处所示,您可以直接请求 ScrollContentPresenter,如下所示:

var BorderChild = VisualTreeHelper.GetChild(MyScrollViewer, 0);
var GridChild = VisualTreeHelper.GetChild(BorderChild, 0);
var ScrollContentPresenterChild = VisualTreeHelper.GetChild(GridChild, 0);

Sorry... it doesn't seems to exist like it does in WPF. Check this link for a handy solution.

Update: Ok... for this you might need to walk the visual tree and some sort of recursive search need to be done. However, assuming you are using the default template for the scrollviewer as seen here, you can directly ask for the ScrollContentPresenter with something like this:

var BorderChild = VisualTreeHelper.GetChild(MyScrollViewer, 0);
var GridChild = VisualTreeHelper.GetChild(BorderChild, 0);
var ScrollContentPresenterChild = VisualTreeHelper.GetChild(GridChild, 0);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文