Silverlight的:以编程方式绑定控件属性 [英] Silverlight: Programmatically binding control properties

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

问题描述

大图:的我有一个基于我设置的属性生成各种文本框,datepickers,康宝等的自定义子控件。该控件嵌入在我SL应用程序中的各个地方。

The big picture: I have a custom child control that generates various textboxes, datepickers, combo etc based on properties that I set. This control is embedded in various places within my SL application.

我通常使用MVVM模式,我想这些动态控件的值绑定回到我的母版页浏览模式。

I generally use the MVVM pattern, and I want to bind the values of these dynamic controls back into my master page view model.

我总是知道会有窗体上8控制,所以我可以有依赖属性到位控件绑定到。然后引用该控件的控制,可以使用与已输入同时保持一个MVVM模式的数据绑定。

I always know that there will be 8 controls on the form so I can have dependency properties in place for the controls to bind to. Then the controls that reference this control, can use binding with the data that has been entered whilst maintaining an MVVM pattern.

问题:的我怎么能动态控件的值绑定到依赖属性编程

The question: How can I bind the values of dynamic controls to dependency properties programmatically?

谢谢,
马克

推荐答案

让我们假设你已经创建了一个简单的文本框,并动态地要添加的Text属性的绑定: -

Lets assume you have created a simple TextBox dynamically and you want to add a binding on the Text property:-

 Binding binding = new Binding("SomeProperty");
 binding.Mode = BindingMode.TwoWay;

 txtBox.SetBinding(TextBox.TextProperty, binding);

在哪里txtBox是要观察动态创建文本框/转变。

Where txtBox is the dynamically created TextBox you want to observe/mutate.

这篇关于Silverlight的:以编程方式绑定控件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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