依赖属性 [英] Dependency Properties

查看:100
本文介绍了依赖属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以解释我的依赖属性在WPF什么,它的用途是什么。我知道有很多关于谷歌的教程吧,但他们教如何创建一个依赖属性。我很困惑,在那里我会使用它。我的意思是,我将在XAML中使用它?如果任何人都可以深入浅出的讲解我来说,那将是巨大的。

Can anybody explain me what a dependency property is in WPF and what is its use. I know there are a lot of tutorials on google for it, but they teach how to create a dependency property. I am confused as to where I would use it. I mean will I use it in XAML? If anybody could explain me in simple terms, that would be great.

这将是很好,如果用XAML一起显示一个简单的例子,有例如,我怎么可能会使用属性,之后我用它会是什么效果。
非常感谢所有的答案..

推荐答案

中列出的许多链接应该给你一个什么样的依赖特性,但在一般情况下,最简单的方法去思考他们的好主意,我相信是这样的:

The many links listed should give you a good idea of what dependency properties are, but in general, the easiest way to think about them I believe is the following:

依赖属性,你需要使用的特性是什么用户界面元素,如果你希望能够使用WPF的数据绑定绑定他们。为了成为目标数据绑定操作,你需要做的属性依赖项属性。

Dependency properties are what you need to use for properties of user interface elements, if you want to be able to bind them using WPF's data binding. In order to be the "Target" of a data binding operation, you'll need to make the property a Dependency Property.

当你实现一个标准类(它变成了控制)的DataContext的,你需要使用INotifyPropertyChanged的,而不是DPS。这允许类是有约束力的源。

When you're implementing a standard class (which becomes the DataContext of a "control"), you'll want to use INotifyPropertyChanged instead of DPs. This allows that class to be a binding "Source".

在一般情况下,你只希望使依赖属性,如果你正在做的东西,将在被绑定XAML,因为目标 UIElement的。例如,假设我们有XAML是这样的:

In general, you'll only want to make Dependency Properties if you're making something that will be bound in XAML, as the Target of a UIelement. For example, say we have XAML like this:

<local:MyControl ControlProperty="{Binding SomeProperty}" />



通常情况下, ControlProperty 将是一个德普。属性,因为它是结合靶,并且SomeProperty将是一个标准的CLR属性(不是DP),在实现INotifyPropertyChanged一个类

Normally, ControlProperty will be a Dep. Property, since it's the binding target, and SomeProperty will be a standard CLR property (not a DP), in a class that implements INotifyPropertyChanged.

这篇关于依赖属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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