In Windows 8.1, when you add a View/Page based upon a Windows 8.1 Basic Page it no longer inherits from LayoutAware class because it no longer exists in Win 8.1. All Basic Pages now inherit directly from Page class and required to do so. Additionally, it no longer has an OnNavigatedTo/OnNavigatedFrom event as the Win8.1 Basic page now leverages the NavigationHelper class and calls this.navigationHelper.LoadState and this.navigationHelper.SaveState event handlers. If using the TipCalc sample and adding a Windows Store Basic Page, TipView, initial page would look like:
public sealed partial class TipView : Page
{
private NavigationHelper navigationHelper;
private ObservableDictionary defaultViewModel = new ObservableDictionary();
/// <summary>
/// This can be changed to a strongly typed view model.
/// </summary>
public ObservableDictionary DefaultViewModel
{
get { return this.defaultViewModel; }
}
/// <summary>
/// NavigationHelper is used on each page to aid in navigation and
/// process lifetime management
/// </summary>
public NavigationHelper NavigationHelper
{
get { return this.navigationHelper; }
}
public TipView()
{
this.InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
this.navigationHelper.SaveState += navigationHelper_SaveState;
}
Since the TipView page now inherits directly from Page, if you change the TipView Page to inherit from MvxStorePage like noted below:
public sealed partial class TipView : MvxStorePage
{
private NavigationHelper navigationHelper;
private ObservableDictionary defaultViewModel = new ObservableDictionary();
Since the Page is a partial class the following error occurs:
Partial declarations of 'TipCalc.CrossPlat.WinStore.Views.TipView' must not specify different base classes.
And even if it would allow for the change in the base class to MvxStorePage, you cannot add base.OnNavigatedTo(e) in LoadState event handler as noted:
private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
base.OnNavigatedTo(e);
}
because e parameter in OnNavigatedTo is looking for NavigationEventArgs vs. LoadStateEventArgs.
So I can't start the app w/TipView page, if I change App.xaml.cs as I should for a MvvmCross project.
I have hacked it to make it work with code noted below:
public sealed partial class TipView : Page, IMvxStoreView, IMvxView, IMvxDataConsumer
{
private NavigationHelper navigationHelper;
private ObservableDictionary defaultViewModel = new ObservableDictionary();
/// <summary>
/// This can be changed to a strongly typed view model.
/// </summary>
public ObservableDictionary DefaultViewModel
{
get { return this.defaultViewModel; }
}
/// <summary>
/// NavigationHelper is used on each page to aid in navigation and
/// process lifetime management
/// </summary>
public NavigationHelper NavigationHelper
{
get { return this.navigationHelper; }
}
protected IMvxSuspensionManager _suspensionManager { get; set; }
private TipViewModel _viewModel { get; set; }
public new IMvxViewModel ViewModel
{
get { return _viewModel; }
set { _viewModel = (TipViewModel)value; }
}
public TipView()
{
this.InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
this.navigationHelper.SaveState += navigationHelper_SaveState;
}
private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
}
private void navigationHelper_SaveState(object sender, SaveStateEventArgs e)
{
}
public void ClearBackStack()
{
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
navigationHelper.OnNavigatedTo(e);
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
navigationHelper.OnNavigatedFrom(e);
}
}
}
Any help will be greatly appreciated as I need to complete my cross-platform PCL project which has a Windows 8.1 implementation.