扩展属性:将属性附加到WPF中的现有类 [英] Extension properties: Attach a property to an existing class in WPF

查看:72
本文介绍了扩展属性:将属性附加到WPF中的现有类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在类(即CollectionViewGroup类)中添加一个属性,我想在XAML中的绑定中使用新属性。 (此新属性'IsChecked'将绑定到复选框的IsChecked属性,该属性是
CollectionViewGroup数据模板的一部分)。任何人都可以建议我如何做到这一点?

I would like to add a property to a class (i.e. the CollectionViewGroup class) and I would like to use the new property in a binding in the XAML. (This new property, 'IsChecked' will be bound to the IsChecked property of a check box, which is part of the CollectionViewGroup data template). Can anyone advice me on how to do this?

我查看了依赖属性,并且能够创建所需的属性,但我没有找到在绑定中使用它的方法在XAML中。

I looked into dependency properties, and was able to create the required property, but I did not find a way of using it in a binding in the XAML.

提前致谢,

Karthik

推荐答案

您的意思是附加属性?

You mean attached properties?

它们仅适用于依赖项对象。

They only work on dependency objects.

检查你想要使用的UI的任何位置肯定是依赖对象。

Check whatever bit of UI you intend using one on is definitely a dependency object.

https://docs.microsoft .com / zh-cn / dotnet / framework / wpf / advanced / attached-properties-overview

https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/attached-properties-overview

https://www.codemag.com/article/1405061/XAML-Magic--附加属性

https://www.codemag.com/article/1405061/XAML-Magic--Attached-Properties


这篇关于扩展属性:将属性附加到WPF中的现有类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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