0

I want to use dependency property which will represent ICarRepository instance.

So I've found this post and based on acc. answer I tried with my example

 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); }
    }
Community
  • 1
  • 1
panjo
  • 3,467
  • 11
  • 48
  • 82

1 Answers1

2

PropertyIdentifier cannot be null (first parameter), pass CLR wrapper property name in it which is Repository.

Regarding PropertyMetadata, you can set that to null. Also you can use other overload where you don't need to pass that value.

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

OR simply avoid last parameter:

public static readonly DependencyProperty RepositoryProperty = 
 DependencyProperty.Register(
       "Repository",
        typeof(ICarRepository ),
        typeof(TreassureControl));
Rohit Vats
  • 79,502
  • 12
  • 161
  • 185
  • Can you be more clear by `example of receiving ICarRepository instance trough xaml`? Where you want to bind that? – Rohit Vats Dec 19 '13 at 11:25