如何将一个控件的属性绑定到另一个控件 [英] how to bind a property of one control to another control

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

问题描述

亲爱的朋友,
我有一个接口类型为ISaveable的用户定义控件(我的用户定义接口),如下所示,
我在主窗体上有一个按钮,如果控件为Isavable,则会启用该按钮.
在下面的代码中可能会使我更有意义.

Dear Friends,
I am having a user defined control of interface type ISaveable (my user defined interface) as follows,
I have a button on the main form that is enabled if the control is Isavable.
May be I can make more sense in following code.

<Button Name="btnSave" Content="Save" IsEnabled="{Binding   ElementName=expMaster, Path= (expMaster.GetType()==typeof(ISavable)) }" />



其中expMaster是实例化为的用户定义控件,



where expMaster is a user defined control instantiated as,

<Employee:EmployeeMaster x:Name="expMaster"  />



从接口ISavable继承Employee master的地方.

请让我知道如何将按钮的isEnabled属性绑定到用户定义的对象类型
我不想在用户定义的控件EmployeeMaster中创建issavable属性.

最好的问候



where Employee master is inherited from interface ISavable.

please let me know how can I bind the isEnabled property of my button to the user defined object type
I don''t want to create issavable property in my user defined control EmployeeMaster.

Best regards

推荐答案

请尝试使用值转换器(IValueConverter)代替路径.
在转换器中,检查value.GetType()并根据需要返回True False .
Instead of the path try and use a value converter (IValueConverter).
In the converter check the value.GetType() and return True or False as needed.


这篇关于如何将一个控件的属性绑定到另一个控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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