如何在WPF DependencyProperty检索上设置断点? [英] How can I put a breakpoint on WPF DependencyProperty retrieval?

查看:54
本文介绍了如何在WPF DependencyProperty检索上设置断点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当WPF 检索 我的自定义DependencyProperty的值时,如何创建一个触发的断点?

我第一次写得不好这个问题.不幸的是,理解为什么我的断点没有被击中并不能解决我真正的问题.这是我应该问的问题.上下搜索,我仍然看不到该怎么做.

如果WPF要绕过我的getter函数,还有其他方法吗?

出于调试目的,我需要它,以便在WPF检索此属性的确切时间检查调试器中控件的状态.

为了刷新,下面是我的自定义依赖项属性

 私有静态只读DependencyPropertyKey ColorizerPropertyKey =DependencyProperty.RegisterReadOnly(nameof(着色器),typeof(SurfaceSeries3DColorizer),typeof(SurfaceDisplay),新的FrameworkPropertyMetadata());私有静态只读DependencyProperty ColorizerProperty =ColorizerPropertyKey.DependencyProperty;公共SurfaceSeries3DColorizer着色器{得到=>(SurfaceSeries3DColorizer)GetValue(ColorizerProperty);私有集=>SetValue(ColorizerPropertyKey,value);} 

...这是绑定到它的XAML

 < tk:SurfaceSeries3D ItemsSource ="{绑定点}"XValueBinding ="X"YValueBinding ="Y"ZValueBinding ="Z"Colorizer ="{绑定着色剂}"/> 

解决方案

有一种方法,但是必须记住,调试对象(调试的应用程序)和调试器本身将变得非常无响应./p>

因此,如果您尝试诊断一些令人讨厌且罕见的错误,则可能会有所帮助.否则,这将毫无用处,因为您的应用几乎无法使用.

转到Visual Studio中的断点窗口,然后选择新建-> 功能断点... .

输入:

  System.Windows.DependencyObject.GetValue 

启用条件复选框并输入您的条件:

  dp == YourNamespace.YourClass.YourDependencyProperty 

在这里, dp GetValue 方法的参数名称(不要更改),而 YourNamespace.YourClass.YourDependencyProperty 是该方法的全名.您的依赖项属性 public 字段(更改).

现在,按F5并享受.

在后台,调试器将检查对 System.Windows.DependencyObject.GetValue 方法的每个调用,并在提供的参数作为您的属性时,调试器将破坏您的应用程序.

请注意,WPF经常调用该方法-这就是您的应用和调试器将变得无响应的原因:将在每次调用时检查一个条件,并且该条件要求在调试器和被调试对象之间进行数据传输.

How can I create a breakpoint triggered when when WPF is retrieving the value of my custom DependencyProperty?

I wrote this question poorly the first time. Unfortunately, understanding why my breakpoint is not hit doesn't solve my real problem. This is the question I should have asked. Searching high and low I still can't see how to do this.

If WPF is going to bypass my getter function, is there some other way?

I need this for debugging purposes, to examine the state of my control live in the debugger at the exact moment WPF retrieves this property.

To refresh, below is my custom dependency property

private static readonly DependencyPropertyKey ColorizerPropertyKey =
    DependencyProperty.RegisterReadOnly(
        nameof(Colorizer),
        typeof(SurfaceSeries3DColorizer),
        typeof(SurfaceDisplay),
        new FrameworkPropertyMetadata());

private static readonly DependencyProperty ColorizerProperty = 
    ColorizerPropertyKey.DependencyProperty;

public SurfaceSeries3DColorizer Colorizer
{
    get => (SurfaceSeries3DColorizer) GetValue(ColorizerProperty);
    private set => SetValue(ColorizerPropertyKey, value);
}

...and this is the XAML that binds to it

<tk:SurfaceSeries3D ItemsSource="{Binding Points}"
                    XValueBinding="X"
                    YValueBinding="Y"
                    ZValueBinding="Z"
                    Colorizer="{Binding Colorizer}"
                    />

解决方案

There is a way for that, but you have to keep in mind that your debuggee (the application you debug) and the debugger itself will become very unresponsive.

So if you're trying to diagnose some nasty and rare occurring bug, this might help. Otherwise, it is pretty useless, because your app will be almost unusable.

Go to the Breakpoints window in Visual Studio and choose New --> Function Breakpoint....

Type in:

System.Windows.DependencyObject.GetValue

Enable the Condition checkbox and enter your condition:

dp == YourNamespace.YourClass.YourDependencyProperty

Here, dp is the GetValue method's argument name (don't change) and YourNamespace.YourClass.YourDependencyProperty is the full name of your dependency property public field (change).

Now, hit F5 and enjoy.

Behind the scenes, the debugger will check each and every call to the System.Windows.DependencyObject.GetValue method, and when the provided argument will be your property, the debugger will break your app.

Note that WPF calls that method very frequently - that's why your app and the debugger will become unresponsive: a condition will be checked on each call, and that condition requires data transfer between debugger and debuggee.

这篇关于如何在WPF DependencyProperty检索上设置断点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆