这是我需要的简化示例: 我有A类,有一个属性Name。 Name属性是异步更改的,无法知道修改何时发生。 为了在视图中显示它的更新值,我在其中连接了propertychanged事件并将其绑定到{Binding A.Name} 。 在VM中它工作正常。 但在我的情况下,有很多自定义属性不应该在类A中。我想在类A中引发propertychanged时, AViewModel的Name属性应该得到通知并提升AViewModel
有没有办法这样做?
C# :
public class A : BaseViewModel { string name; public string Name { get { return name; } set { Set(()=> Name, ref name, value); } } } public class AViewModel : BaseViewModel { A a; public A A { get { return a; } set { Set(()=> A, ref a, value); } } public string Name { get { return A.Name; } set { Set(()=> Name, ref A.Name, value); } } }XAML:
<TextBox Text="{Binding Name}" />Here is a simplified example of what i need: I have class A that have a property Name. the Name property is changed asynchronously and there is no way to know when the modification occurs. In order to show the updated value of it in the view, I wired a propertychanged event in it and bind it with {Binding A.Name}. In the VM it works fine. But in my case, there is a lot of custom properties that shouldn't be in the class A. I'm thinking once propertychanged is raised in class A, the Name property in AViewModel should get notified and raise the OnPropertyChanged too
is there any way to do so ?
C# :
public class A : BaseViewModel { string name; public string Name { get { return name; } set { Set(()=> Name, ref name, value); } } } public class AViewModel : BaseViewModel { A a; public A A { get { return a; } set { Set(()=> A, ref a, value); } } public string Name { get { return A.Name; } set { Set(()=> Name, ref A.Name, value); } } }XAML :
<TextBox Text="{Binding Name}" />最满意答案
例如,A类必须具有经典的C#事件,因此AViewModel可以订阅它。
The class A must have a classic C# event, for example, so the AViewModel can subscribe it.
更多推荐
发布评论