我正在對棱鏡(Unity)進行第一次嚴重攻擊。我有一個帶有工具欄控件的模塊,它可以正確地加載到它應該的區域。此工具欄是一個帶有ItemsSource數據綁定到其ViewModel上的ToolButtons屬性的列表框,該構造函數爲ToolButtons集實例化並添加了三個ToolButton。我的ToolButton類有三個自定義DependencyProperties:Title(字符串),ButtonFace(圖像),ActiveDocumentCount(int)。樣式由具有Style和相關ControlTemplate的模塊中的資源字典處理。我有數據綁定的屬性,但沒有值或圖像顯示(樣式中的其他元素是然而)通過TemplateBinding。如何在MVVM/Prism中獲得數據綁定調試信息?
我想調試數據綁定,但無濟於事。在輸出窗口中我沒有得到任何相關的按摩,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));
}
你可以顯示你用於註冊你的DependencyProperties的代碼位嗎?你是否也在任何地方對它們進行SetValues?因爲那會破壞綁定。 – 2012-07-31 19:06:30
將ToolButton類添加到我的帖子中。我在整個使用SetValue。我不知道SetValue會破壞綁定。我該如何運行二傳手? – CodeWarrior 2012-08-01 02:56:51
那些DP看起來沒問題CLR支持的屬性中的SetValue是好的....但如果你是任何人通過調用它們(通過代碼)設置本地值,那麼這將破壞綁定。 http://wpf.2000things.com/2010/12/06/147-use-setcurrentvalue-when-you-want-to-set-a-dependency-property-value-from-within-a-control/ – 2012-08-01 09:03:27