我可以绑定一个WPF控件到现场的财产? [英] Can I bind a WPF control to a field's property?

查看:118
本文介绍了我可以绑定一个WPF控件到现场的财产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我需要分割类之间的一些功能,我在以下情况下到达

Because I needed to split some functionality between classes, I've arrived at the following situation

XAML code

xaml code

<CheckBox IsChecked="{Binding MyObjectField.MyBoolean}"  />

视图模型

...
public MyInternalObject MyObjectField;
...

MyObject来类

MyObject class

public class MyInternalObject {
    ...
    public bool MyBoolean { get; set; }
    ...
}

它不工作,除非我在复制视图模型类MyBoolean属性。

It does not work unless I replicate the MyBoolean property in the View Model class.

public bool MyBoolean 
{ 
    get { return MyInternalObject.MyBoolean; }
    set { MyInternalObject.MyBoolean=value; }
}

有没有人有一个想法?

Does anyone have an idea?

推荐答案

没有你不能。由于绑定系统使用反射来找到

No you cant . Because binding system uses Reflection to find the

属性,DataContext的(即你的VM)

Property in DataContext(i.e your VM)

它不寻求领域。我希望这会有所帮助。

It does not look for fields . I hope this will help.

这篇关于我可以绑定一个WPF控件到现场的财产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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