繁体   English   中英

将自定义用户控件绑定到RegionContext的属性

[英]Binding Custom User Control to a RegionContext's Property

我正在通过编写一个小型HR应用程序来学习Prism(版本5)框架。

我的EmployeeSummaryView是一个简单的主详细信息页面,它使用选项卡控件更好地组织Person类型的属性。 此选项卡控件具有区域上下文绑定到CurrentEmployee。

public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public DateTime Birthday { get; set; }
    public string PhoneNumber { get; set; }
    public Address MailingAddress { get; set; }
    public Person EmergencyContact { get; set; }
}

我正在苦苦挣扎的地方在“联系信息”选项卡上。 在这里,我使用自定义用户控件来编辑邮件地址。 建立绑定的第一个直觉是执行以下操作:

<local:EditAddressView DataContext="{Binding CurrentEmployee.MailingAddress}"/>

但是我对Prism和MVVM的了解越多,这种气味就越多。

将自定义控件绑定到RegionContext上的属性的合适方法是什么?

通过绑定到模型而不是ViewModel,您将自己陷入困境。 用ViewModels包装模型,然后绑定到这些模型。

public class PersonViewModel
{
    public PersonViewModel(Person person)
    {
       ...
       MailingAddress = new AddressViewModel(person.address);
    }

    public AddressViewModel MailingAddress { get; private set; }
}

暂无
暂无

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

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