Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding from code to a custom attached property in WinRT/UWP

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?

like image 282
Thomas Levesque Avatar asked Sep 17 '16 18:09

Thomas Levesque


2 Answers

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.

like image 198
Grace Feng Avatar answered Oct 26 '22 13:10

Grace Feng


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?

like image 2
Anthony Wieser Avatar answered Oct 26 '22 15:10

Anthony Wieser