I'm trying to create a binding from code in a library that targets multiple frameworks (WPF, WinRT, UWP etc), and I'm hitting a brick wall. The property I'm trying to bind to is a custom attached property. In WPF, I can pass the DependencyProperty
itself as the binding path:
new PropertyPath(MyClass.MyAttachedProperty)
But in WinRT the PropertyPath
class only accepts a string. I tried to pass the name of the property like this:
new PropertyPath("(MyClass.MyAttachedProperty)")
but of course it doesn't work, since my class is not in the default namespace. In XAML I could map the namespace to a prefix and use that prefix, but as far as I know it's not possible to do this from code.
Is there any way to create this binding in code?
Good question, after researching and discussing we've confirmed that in UWP, we cannot programmatically binding to custom attached property. Sadly.
You may submit a request to add this new features for development through the Windows Feedback tool.
It looks as though there may be a solution here, which involves using XamlReader.Load and a resource dictionary containing the binding, to get the loader to do the work for you.
How can I bind to a custom attached property in c# from code behind in a windows store app?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With