2013-05-01 71 views
0

我有一個綁定到該DataTemplateSelector一個ContentControl中:更改ContentControl中的內容與按鈕單擊

public class PropertyPageTemplateSelector : DataTemplateSelector 
{ 
    protected override DataTemplate SelectTemplateCore(object item, DependencyObject container) 
    { 
     if (item == null) return base.SelectTemplateCore(item, container); 

     var contentControl = (ContentControl)container; 
     var templateKey = (string)item; 

     return (DataTemplate)contentControl.Resources[templateKey]; 
    } 
} 

我怎樣才能改變加載的資源在ContentControl中有一個按鈕,點擊?我不能直接調用該方法,因爲它受到保護...

回答

0

由於該項目是一個字符串,ContentControl的內容是一個字符串。您只需將ContentControl的內容更改爲所需的字符串即可。

+0

好的,謝謝你的工作,但我怎樣才能改變其他類的內容? – Cilenco 2013-05-01 16:29:23

+0

@Cilenco這很難回答,因爲它確實是一個應用程序體系結構問題,但標準做法是創建一個類,作爲您的ContentControl內容將綁定到的屬性的頁面視圖模型。請看看這個示例,看看是否有幫助:[link](http://code.msdn.microsoft.com/windowsapps/Data-Binding-7b1d67b5) – Murkaeus 2013-05-01 20:16:22