0
我在嘗試構建使用WinRT/Metro進行MVVM的組合部件。我建立了自己ViewBase其派生的從用戶控件,所以我可以用它來擴展自己的看法:如何在Metro/WinRT中擴展視圖
using System;
using System.Linq;
using Windows.UI.Xaml.Controls;
using System.Collections.Generic;
public abstract class ViewBase : UserControl
{
/// <summary>
/// Initializes a new instance of the ViewBase class.
/// </summary>
public ViewBase() : base()
{
BindViewModelLocatorToView(viewModelLocator: GetViewModelLocator());
}
/// <summary>
/// Defines a method that returns a view model locator to be used with this class.
/// </summary>
protected abstract IViewModelLocator GetViewModelLocator();
/// <summary>
/// Defines a method that Bind's the view model provided by the view locator to the view's data context.
/// </summary>
private void BindViewModelLocatorToView(IViewModelLocator viewModelLocator)
{
if (viewModelLocator != null)
{
DataContext = viewModelLocator.ViewModel;
}
}
}
當我儘量延長我使用的視圖中的用戶控件我得到一個錯誤,這部分的家長必須匹配生成的部分父項。當然,我不能改變生成的父類,因爲它只是改變重建。
我注意到在示例應用程序包括他們使用相同的概念與佈局知道頁面,但我不知道他們如何設置設計器生成部分匹配。
有誰知道這是怎麼完成的?