如何在MVVM / Prism中获取数据绑定调试信息?

时间:2012-07-23 04:25:57

标签: wpf debugging data-binding mvvm prism

我正在第一次认真进军Prism(Unity)。我有一个带有工具栏控件的模块,可以(正确地)加载到它应该的区域。此工具栏是一个列表框,其ItemsSource数据绑定到其ViewModel上的ToolButtons属性,该构造函数实例化并向ToolButtons集合添加三个ToolButtons。

我的ToolButton类有三个自定义DependencyProperties:Title(字符串),ButtonFace(Image),ActiveDocumentCount(int)。样式由具有Style和关联ControlTemplate的模块中的资源字典处理。我已经对数据进行了数据绑定,但是没有通过TemplateBinding显示值或图像(样式中的其他元素)。

我正在尝试调试数据绑定,但无济于事。我没有在“输出”窗口中获得任何相关的按摩,this blog中的第二和第三个建议也没有产生任何输出。我想如果我能得到详细的(即PresentationTraceSources.TraceLevel = High)输出,我可以弄清楚数据绑定前端发生了什么。

编辑:

工具按钮类

public class ToolButton : Button
{
    public ToolButton()
    {
        //DefaultStyleKeyProperty.OverrideMetadata(typeof(ToolButton), new FrameworkPropertyMetadata(typeof(ToolButton)));
    }

    public Image ButtonFace
    {
        get { return (Image)this.GetValue(ButtonFaceProperty); }
        set { this.SetValue(ButtonFaceProperty, value); }
    }
    public static readonly DependencyProperty ButtonFaceProperty =
        DependencyProperty.Register("ButtonFace", typeof(Image), typeof(ToolButton), new PropertyMetadata(null));

    public string Title
    {
        get { return (string)this.GetValue(TitleProperty); }
        set { this.SetValue(TitleProperty, value); }
    }

    public static readonly DependencyProperty TitleProperty =
        DependencyProperty.Register("Title", typeof(string), typeof(ToolButton), new PropertyMetadata(""));

    public int OpenRecordCount
    {
        get { return (int)this.GetValue(OpenRecordCountProperty); }
        set { this.SetValue(OpenRecordCountProperty, value); }
    }

    public static readonly DependencyProperty OpenRecordCountProperty =
        DependencyProperty.Register("OpenRecordCount", typeof(int), typeof(ToolButton), new PropertyMetadata(null));

}

1 个答案:

答案 0 :(得分:1)