[英]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.