简体   繁体   English

WPF数据绑定到返回类的属性

[英]WPF Data Binding to property that returns class

I have a class that encapsulates several other classes that have more detailed definitions. 我有一个封装了其他几个具有更详细定义的类的类。 For example 例如

class MyProperties
{
    SubProperties Props { get; set; }
}

class SubProperties
{
    double MyValue { get; set; }
}

Is there any way to bind to this subproperty, "MyValue"? 有什么方法可以绑定到该子属性“ MyValue”吗? I'd like to have a label display the value of MyValue by referencing MyProperties 我想通过引用MyProperties使标签显示MyValue的值

It works just like in a C# code, you access property with dot operator. 就像在C#代码中一样,您可以使用点运算符访问属性。

<Label Content="{Binding Props.MyValue}" />

If that doesn't work, check if your data context is set properly and your view models implement INotifyPropertyChanged interface. 如果这不起作用,请检查您的数据上下文是否设置正确,并且您的视图模型实现了INotifyPropertyChanged接口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM