试图了解的DependencyProperty [英] Trying to understand of DependencyProperty

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

问题描述

作为新的WPF,它显然是惊人的改变,绑定,启用和以其他方式操纵能力。我试图让正在发生的事情的心理概述,并希望一些可以证实或纠正我的读数。

Being new to WPF, and its apparently amazing ability to change, bind, enable, and otherwise manipulate. I'm trying to get a mental overview of what is happening and hope some can either confirm or correct my readings.

WPF之前,你必须委托和事件。你可以有十几种控制所有听(通过已注册的事件),所以当事件触发,所有其他控件会自动通知,并可以但他们是如此codeD行事。如...

Before WPF, you have delegates and events. You could have a dozen controls all listening (via being registered to the event), so when the event fires, all other controls will be notified automatically and can act on however they were so coded. Such as...

从code的背后,你会做这样的事情。

From Code Behind, you would do something like

GotFocus += MyMethodToDoSomething;

然后,签名方法

private void MyMethodToDoSomething(object sender, RoutedEventArgs e)
{
  .. do whatever
}

此外,通过使用标准的getter / setter,二传手可以调用它自己的方法在自己的课上做的东西,每次有人试图获取或设置一个值

Additionally, by using standard getter / setter, the setter can call its own methods in its own class to do something every time someone tries to get or set a value

private int someValue;
public int SomeValue
{
   get { this.DoSomeOtherThing();
         return someValue;
       }

   set { this.DoAnotherThing();
        someValue = value;
}

现在,有依赖属性,和一/双向绑定。我的理解(我认为)关于单向模拟更多的是只读操作。

Now, there's dependency properties, and the one/two-way binding. I understand (I think) about one-way to simulate more of a read-only operation.

总之,随着双向绑定,依赖关系自动通知任何人。根据关于在分别的源或目标的变化,没有明确的检查,如果事情已经订阅了一个事件,该框架自动处理变动的宣布到各自的控制(目标或源)。

Anyhow, with two way binding, the dependencies automatically notify anyone "depending" on a change in either the source or target respectively, without an explicit check if something has subscribed to an event, the framework automatically handles the announcing of the change to the respective controls (target or source).

那么,让我通过这个方案出与旧添加/编辑保存/取消维护形式。
在旧的框架,如果有人上添加或编辑按钮点击后,所有的数据输入字段将成为已启用为一个新的记录或者空白数据或编辑现有数据。同时,添加/编辑按钮会被禁用,但保存/取消按钮现在将被启用。

So, let me through this scenario out with an old Add/Edit Save/Cancel maintenance form. In an older framework, if someone clicked on an add or edit button, all the data entry fields would become "enabled" with either blank data for a new record, or editing existing data. At the same time, the add/edit buttons would become disabled, but the Save/Cancel buttons would now become enabled.

同样,当通过保存完毕/取消,这将禁用所有的输入字段,保存/取消,并重新启用添加/编辑按钮。

Likewise when finished via Save/Cancel, it would disable all the entry fields, save/cancel, and re-enable the Add/Edit buttons.

我不明白怎么这么此类情况将这种依赖房地产的情况(但)下进行处理,但我是关闭?我也明白,你可以绑定到几乎所有的东西,包括配色方案,显示/隐藏,字体等...但我承担想要真正掌握这个东西小步骤。

I don't quite understand how such this type of scenario would be handled under this dependency property scenario (yet), but am I close? I also understand you can bind to almost anything, including color schemes, show/hide, fonts, etc... But I'm taking small steps on trying to really grasp this stuff.

感谢。

推荐答案

海报已经要求我重新发布作为回答我的意见。乐意效劳: - )

The poster has requested that I repost my comment as an answer. Happy to oblige :-)

  • The video presentation I referred to: http://blog.lab49.com/archives/2650
  • Bonus link: awesome WPF article in MSDN: http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
  • And in case you didn't know about it, there's a chapter in the online documentation: http://msdn.microsoft.com/en-us/library/ms752914.aspx

另外,我发现这本书非常有帮助: http://www.amazon.com/ WPF-4-偷跑 - 亚当森/ DP / 0672331195

Also I've found this book very helpful: http://www.amazon.com/WPF-4-Unleashed-Adam-Nathan/dp/0672331195

我自己的经验,WPF会涉及到一堆不同资源之间早在我试图让我的程序工作。有这么多的东西,在WPF这真的很难让这一切在你的头上,你正在学习它。

My own experience with WPF involves going back between a bunch of different resources as I try to get my program to work. There's so much stuff in WPF it's really hard to keep it all in your head as you are learning it.

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

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