
Untitled
By: a guest on
Aug 10th, 2012 | syntax:
None | size: 0.92 KB | hits: 9 | expires: Never
How to extend views in 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;
}
}
}