I am playing around trying to build the composite parts for doing MVVM with WinRT / Metro. I have built myself ViewBase which derive’s from UserControl so I could use it to extend my views:
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;
}
}
}
When I try to extend the UserControl I am using as a view I get an error that this partial’s parent must match the generated partial’s parent. Of course I can’t change the generated classes parent as it simply changes back on rebuild.
I notice in the sample apps included they are using the same concept with Layout aware page but I am not sure how they set the designer generated partial to match.
Does anyone know how this is done?
You need to change the root element in your XAML to
<ns:ViewBase>, wherensis declared as the namespace your class is in.