简体   繁体   English

从代码绑定到WinRT / UWP中的自定义附加属性

[英]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. 我试图从针对多个框架(WPF,WinRT,UWP等)的库中的代码创建绑定,但遇到了麻烦。 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: 在WPF中,我可以将DependencyProperty本身作为绑定路径传递:

new PropertyPath(MyClass.MyAttachedProperty)

But in WinRT the PropertyPath class only accepts a string. 但是在WinRT中, PropertyPath类仅接受字符串。 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. 在XAML中,我可以将名称空间映射到前缀并使用该前缀,但是据我所知,不可能从代码中做到这一点。

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. 很好的问题,经过研究和讨论,我们已经确认在UWP中,我们无法以编程方式绑定到自定义附加属性。 Sadly. 可悲的是。

You may submit a request to add this new features for development through the Windows Feedback tool. 您可以提交请求,以通过Windows反馈工具添加此新功能以进行开发。

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. 似乎这里有解决方案,其中涉及使用XamlReader.Load和包含绑定的资源字典,以使加载程序为您完成工作。

How can I bind to a custom attached property in c# from code behind in a windows store app? 如何从Windows应用商店中后面的代码绑定到C#中的自定义附加属性?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM