如何在“依赖属性已更改”上设置断点?
我们的 Silverlight 应用程序包含一个第三方控件,其中包含一些 ScrollBar(除其他外)。为了解决问题,我希望每当第三方控件修改其任何滚动条的最小或最大属性时都能够在调试器中停止。然后我将能够查看堆栈跟踪并了解有关正在发生的情况的更多信息。
如果我对 ScrollBars 的 Value 属性感兴趣,那一切都很简单 - ScrollBar 有一个 ValueChanged 事件,因此我只需添加一些一次性代码来在 ScrollBar 上挂钩该事件,在事件处理程序中设置断点,然后进行调试离开。但是MinimumChanged 或MaximumChanged 没有对应的CLR 事件,所以事情不会那么简单。
我遇到了一篇博客文章,其中讨论了 使用 DependencyPropertyDescriptor 获取依赖属性更改事件,但不幸的是,DependencyPropertyDescriptor 在 Silverlight 中不存在。
如何才能设置一个断点,每当 ScrollBar 的 Maximum 和 Maximum 属性发生变化时就会触发该断点?
Our Silverlight app contains a third-party control, which contains some ScrollBars (among other things). In order to troubleshoot a problem, I want to be able to stop in the debugger whenever the third-party control modifies the Minimum or Maximum properties of any of its scrollbars. Then I'll be able to look at the stack trace and learn more about what's going on.
If I was interested in the ScrollBars' Value property, that would all be easy -- ScrollBar has a ValueChanged event, so I could just add some throwaway code that hooks that event on the ScrollBar, set a breakpoint inside my event handler, and debug away. But there are no corresponding CLR events for MinimumChanged or MaximumChanged, so it won't be that simple.
I ran across a blog post that talks about using DependencyPropertyDescriptor to get dependency property change events, but unfortunately, DependencyPropertyDescriptor doesn't exist in Silverlight.
How can I get to the point where I can set a breakpoint that fires whenever the ScrollBar's Minimum and Maximum properties change?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想到了以下想法:
这种方法应该允许您设置一个断点,每当“最小值”或“最大值”属性发生更改时就会触发该断点。但是,我不能保证您会得到对您有帮助的堆栈跟踪。
用户控件的代码隐藏可能如下所示:
假设您有一个带有
x:Name="someScrollBar"
的 ScrollBar,则可以将如下内容添加到 XAML 中:The following idea springs to my mind:
This approach should allow you to set a breakpoint that fires whenever the Minimum or Maximum property changes. However, I can't guarantee that you'll get a stacktrace that will help you.
The code-behind of the user control could look something like this:
Assuming that you have a ScrollBar with
x:Name="someScrollBar"
, you could then add something like the following to your XAML: