HCL
HCL

Reputation: 36815

Bind a readonly DependencyProperty to another readonly DependencyProperty

I have a class that contains a readonly DependencyProperty. From this class, I want to bind to the readonly DependencyProperty to another readonly DepenendencyProperty of another class (create binding from code).

Is there a possibility to do this? SetBinding() seems not to have a overload that takes a DependencyPropertyKey as a parameter? Neither seems the BindingOperations-class to provide such functionality.

The question can also be formulated: Can I create a binding for a readonly DependencyProperty if I have the DependencyPropertyKey?

Upvotes: 5

Views: 964

Answers (2)

MikNik
MikNik

Reputation: 84

Any good suggestions on how to implement this?

One could try to implement a private RW dependency property, bind the original RO to it, and in RW's callback modify the exposing RO. But this sounds like a hack. Any better options?

Upvotes: 0

Ramon de Klein
Ramon de Klein

Reputation: 5706

This isn't possible because the FrameworkElement.SetBinding method only accepts a DependencyProperty as its first parameter. It would have been great if it would also accept a DependencyPropertyKey instead. Because the key isn't visible outside the class, it would still be read-only outside the class, but from within the class you could use it for a binding. Unfortunately, this isn't possible.

Upvotes: 2

Related Questions