Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 10th, 2012  |  syntax: None  |  size: 0.92 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to extend views in Metro / WinRT
  2. using System;
  3. using System.Linq;
  4. using Windows.UI.Xaml.Controls;
  5. using System.Collections.Generic;
  6.  
  7. public abstract class ViewBase : UserControl
  8. {
  9.     /// <summary>
  10.     /// Initializes a new instance of the ViewBase class.
  11.     /// </summary>
  12.     public ViewBase() : base()
  13.     {
  14.         BindViewModelLocatorToView(viewModelLocator: GetViewModelLocator());
  15.     }
  16.  
  17.     /// <summary>
  18.     /// Defines a method that returns a view model locator to be used with this class.
  19.     /// </summary>
  20.     protected abstract IViewModelLocator GetViewModelLocator();
  21.  
  22.  
  23.     /// <summary>
  24.     /// Defines a method that Bind's the view model provided by the view locator to the view's data context.
  25.     /// </summary>
  26.     private void BindViewModelLocatorToView(IViewModelLocator viewModelLocator)
  27.     {
  28.         if (viewModelLocator != null)
  29.         {
  30.             DataContext = viewModelLocator.ViewModel;
  31.         }
  32.     }
  33. }