Skip to content

Commit

Permalink
#506 Migrate DisplayRootViewFor<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
Nigel Sampson committed Feb 26, 2018
1 parent 86a1edd commit 7f36022
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Caliburn.Micro.Platform/Platforms/UWP/CaliburnApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
Expand Down Expand Up @@ -257,7 +259,7 @@ protected void DisplayRootView<T>(object parameter = null)
/// Locates the view model, locates the associate view, binds them and shows it as the root view.
/// </summary>
/// <param name="viewModelType">The view model type.</param>
protected void DisplayRootViewFor(Type viewModelType)
protected async Task DisplayRootViewForAsync(Type viewModelType, CancellationToken cancellationToken)
{
Initialize();

Expand All @@ -266,21 +268,24 @@ protected void DisplayRootViewFor(Type viewModelType)

ViewModelBinder.Bind(viewModel, view, null);

var activator = viewModel as IActivate;
if (activator != null)
activator.Activate();
if (viewModel is IActivate activator)
await activator.ActivateAsync(cancellationToken);

Window.Current.Content = view;
Window.Current.Activate();
}

protected Task DisplayRootViewForAsync(Type viewModelType) => DisplayRootViewForAsync(viewModelType, CancellationToken.None);

/// <summary>
/// Locates the view model, locates the associate view, binds them and shows it as the root view.
/// </summary>
/// <typeparam name="T">The view model type.</typeparam>
protected void DisplayRootViewFor<T>()
protected Task DisplayRootViewForAsync<T>(CancellationToken cancellationToken)
{
DisplayRootViewFor(typeof(T));
return DisplayRootViewForAsync(typeof(T), cancellationToken);
}

protected Task DisplayRootViewForAsync<T>() => DisplayRootViewForAsync<T>(CancellationToken.None);
}
}

0 comments on commit 7f36022

Please sign in to comment.