2013-12-19 21 views
0

我想使用依賴屬性代表ICarRepository實例。在這個實際例子中使用wpf中的依賴屬性

所以我找到了this post和根據acc。答案我與我的例子試圖

public static readonly DependencyProperty RepositoryProperty = DependencyProperty.Register(
    null, 
    typeof(ICarRepository), 
    typeof(TreassureControl), 
    **new PropertyMetadata(??????)** what to put here? 
    ); 

    public ICarRepository Repository 
    { 
     get { return (ICarRepository)GetValue(RepositoryProperty); } 
     set { SetValue(RepositoryProperty, value); } 
    } 

回答

2

PropertyIdentifier不能爲空(第一個參數),通過它CLR包裝屬性名稱是Repository

關於PropertyMetadata,您可以將其設置爲null。您也可以在不需要傳遞該值的情況下使用其他超載。

public static readonly DependencyProperty RepositoryProperty = 
DependencyProperty.Register(
     "Repository", 
     typeof(ICarRepository), 
     typeof(TreassureControl), 
     new PropertyMetadata(null)); 

或乾脆避免最後一個參數:

public static readonly DependencyProperty RepositoryProperty = 
DependencyProperty.Register(
     "Repository", 
     typeof(ICarRepository), 
     typeof(TreassureControl)); 
+0

你可以通過'例如接收ICarRepository例如槽xaml'的更清楚了嗎?你想綁定的地方? –