从代码绑定到WinRT/UWP中的自定义附加属性 [英] Binding from code to a custom attached property in WinRT/UWP

查看:42
本文介绍了从代码绑定到WinRT/UWP中的自定义附加属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从针对多个框架(WPF,WinRT,UWP等)的库中的代码创建绑定,但遇到了麻烦.我要绑定到的属性是一个 custom 附加属性.在WPF中,我可以将DependencyProperty本身作为绑定路径:

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)

但是在WinRT中,PropertyPath类仅接受字符串.我试图像这样传递属性的名称:

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)")

但是它当然不起作用,因为我的课程不在默认名称空间中.在XAML中,我可以将名称空间映射到一个前缀并使用该前缀,但是据我所知,不可能从代码中做到这一点.

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?

推荐答案

很好的问题,经过研究和讨论,我们确认在UWP中,我们无法以编程方式绑定到自定义附加属性.可悲的是.

Good question, after researching and discussing we've confirmed that in UWP, we cannot programmatically binding to custom attached property. Sadly.

您可以通过Windows反馈工具提交添加此新功能以进行开发的请求.

You may submit a request to add this new features for development through the Windows Feedback tool.

这篇关于从代码绑定到WinRT/UWP中的自定义附加属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆