[英]How do I call an attribute value from one model class to another model class?
I have an attribute called ServiceName
in my Service.cs
class, and I want the same value to show in another class called Booking.cs
without me having to enter it again. 我在
Service.cs
类中有一个名为ServiceName
的属性,并且我希望在另一个类Booking.cs
显示相同的值,而无需再次输入。
public class Service
{
public string ServiceName { get; set; }
}
public class Booking
{
[DisplayName("Service Chosen")]
public string ServiceName { get; set; }
}
So you must communicate between two class so you must use something like Prism EventAggregator With this you can send value if its change like 因此,您必须在两个类之间进行通信,因此您必须使用Prism EventAggregator之类的东西,如果它的更改如
public string ServiceName
{
get { return _serviceName; }
set
{
_serviceName = value;
EventAggregator.GetEvent<eventname>().Publish(_serviceName);
}
}
and subscribe using EventAggregator.GetEvent<eventname>().Subscribe(YourSubscribeMethod);
并使用
EventAggregator.GetEvent<eventname>().Subscribe(YourSubscribeMethod);
you can read about it here https://prismlibrary.github.io/docs/event-aggregator.html 您可以在这里阅读有关内容https://prismlibrary.github.io/docs/event-aggregator.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.