Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
jerrynixon committed Feb 12, 2016
2 parents 853b56e + 9b2d0f4 commit fd2cece
Showing 7 changed files with 47 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Snippets/T10_ViewModelFull.snippet
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[public class $name$ViewModel : Mvvm.ViewModelBase
<![CDATA[public class $name$ViewModel : ViewModelBase
{
public $name$ViewModel()
{
@@ -98,4 +98,4 @@
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
</CodeSnippets>
6 changes: 3 additions & 3 deletions Template10 (Library)/Behaviors/NavButtonBehavior.cs
Original file line number Diff line number Diff line change
@@ -158,17 +158,17 @@ public static Visibility CalculateBackVisibility(Frame frame)
var touchmode = UIViewSettings.GetForCurrentView().UserInteractionMode == UserInteractionMode.Touch;

// mobile always has a visible back button
var mobilefam = ResourceContext.GetForCurrentView().QualifierValues["DeviceFamily"].Equals("Mobile");
var mobilefam = "Windows.Mobile".Equals(Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily, StringComparison.OrdinalIgnoreCase);
if (mobilefam && touchmode)
// this means phone, not continuum, which uses hardware (or steering wheel) back button
return Visibility.Collapsed;

// handle iot
var iotfam = ResourceContext.GetForCurrentView().QualifierValues["DeviceFamily"].Equals("IoT");
var iotfam = "Windows.IoT".Equals(Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily, StringComparison.OrdinalIgnoreCase);
if (!iotfam)
{
// simply don't know what to do with else
var desktopfam = ResourceContext.GetForCurrentView().QualifierValues["DeviceFamily"].Equals("Desktop");
var desktopfam = "Windows.Desktop".Equals(Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily, StringComparison.OrdinalIgnoreCase);
if (!desktopfam)
return Visibility.Collapsed;
}
15 changes: 14 additions & 1 deletion Template10 (Library)/Common/BootStrapper.cs
Original file line number Diff line number Diff line change
@@ -58,7 +58,14 @@ public virtual T Resolve<T>(Type type)
/// If a developer overrides this method, and leaves the DataContext of a page null, then BootStrapper
/// will atttempt to fill the DataContext the return value of this method.
/// </summary>
[Obsolete("Use ResolveForPage(Page, NavigationService) instead")]
public virtual Services.NavigationService.INavigable ResolveForPage(Type page, NavigationService navigationService) => null;

/// <summary>
/// If a developer overrides this method, the developer can resolve DataContext or unwrap DataContext
/// available for the Page object when using a MVVM pattern that relies on a wrapped/porxy around ViewModels
/// </summary>
public virtual Services.NavigationService.INavigable ResolveForPage(Page page, NavigationService navigationService) => ResolveForPage(page.GetType(), navigationService);

#endregion

@@ -454,7 +461,13 @@ private async Task InitializeFrameAsync(IActivatedEventArgs e)
await OnInitializeAsync(e);

// this "unused" bit is very important because of a quirk in ResourceThemes
try { var unused = Application.Current.Resources["ExtendedSplashBackground"]; }
try
{
if(Application.Current.Resources.ContainsKey("ExtendedSplashBackground"))
{
var unused = Application.Current.Resources["ExtendedSplashBackground"];
}
}
catch { /* this is okay */ }

// setup custom titlebar
3 changes: 2 additions & 1 deletion Template10 (Library)/Controls/HamburgerMenu.xaml
Original file line number Diff line number Diff line change
@@ -62,7 +62,8 @@
IsChecked="{Binding IsChecked, Mode=TwoWay}"
IsEnabled="{Binding IsEnabled, Mode=TwoWay}" Loaded="NavButton_Loaded"
RightTapped="NavButton_RightTapped" Tag="{x:Bind Content}"
Tapped="NavButton_Tapped" Visibility="{Binding Visibility, Mode=TwoWay}">
Tapped="NavButton_Tapped" Visibility="{Binding Visibility, Mode=TwoWay}"
ToolTipService.ToolTip="{Binding Path=(ToolTipService.ToolTip)}">
<RadioButton.Template>
<ControlTemplate TargetType="RadioButton">
<ToggleButton MinWidth="48" MinHeight="48" MaxWidth="{TemplateBinding MaxWidth}"
6 changes: 3 additions & 3 deletions Template10 (Library)/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -5,13 +5,13 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Sample")]
[assembly: AssemblyTitle("Template10Library")]
[assembly: AssemblyDescription("http://aka.ms/template10")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Sample")]
[assembly: AssemblyProduct("Template10Library")]
[assembly: AssemblyCopyright("Copyright © 2015-2016")]
[assembly: AssemblyTrademark("Sample")]
[assembly: AssemblyTrademark("http://jerrynixon.com")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.0.*")]
[assembly: ComVisible(false)]
Original file line number Diff line number Diff line change
@@ -73,6 +73,20 @@ await WindowWrapper.Current().Dispatcher.DispatchAsync(async () =>
}, 1);
};
}

private INavigable ResolveForPage(Page page)
{
if (!(page.DataContext is INavigable) | page.DataContext == null)
{
// to support dependency injection, but keeping it optional.
var viewModel = BootStrapper.Current.ResolveForPage(page, this);
if ((viewModel != null))
{
return viewModel;
}
}
return (INavigable)page.DataContext;
}

// before navigate (cancellable)
async Task<bool> NavigatingFromAsync(bool suspending, NavigationMode mode)
@@ -86,7 +100,7 @@ async Task<bool> NavigatingFromAsync(bool suspending, NavigationMode mode)
XamlUtils.UpdateBindings(page);

// call navagable override (navigating)
var dataContext = page.DataContext as INavigable;
var dataContext = ResolveForPage(page);
if (dataContext != null)
{
dataContext.NavigationService = this;
@@ -115,7 +129,7 @@ async Task NavigateFromAsync(bool suspending)
if (page != null)
{
// call viewmodel
var dataContext = page.DataContext as INavigable;
var dataContext = ResolveForPage(page);
if (dataContext != null)
{
dataContext.NavigationService = this;
@@ -145,16 +159,8 @@ async Task NavigateToAsync(NavigationMode mode, object parameter, object frameCo
pageState?.Clear();
}

if (!(page.DataContext is INavigable) | page.DataContext == null)
{
// to support dependency injection, but keeping it optional.
var viewmodel = BootStrapper.Current.ResolveForPage(page.GetType(), this);
if (viewmodel != null)
page.DataContext = viewmodel;
}

// call viewmodel
var dataContext = page.DataContext as INavigable;
var dataContext = ResolveForPage(page);

if (dataContext != null)
{
// prepare for state load
10 changes: 5 additions & 5 deletions Template10 (Services)/ToastService/ToastHelper.cs
Original file line number Diff line number Diff line change
@@ -133,7 +133,7 @@ public ToastNotification BuildToastText03(string title, string content, string a
public ToastNotification BuildToastText04(string title, string content, string content2, string arg = null)
{
// build toast
var template = ToastTemplateType.ToastText02;
var template = ToastTemplateType.ToastText04;
var xml = ToastNotificationManager.GetTemplateContent(template);
var elements = xml.GetElementsByTagName(textNode);

@@ -156,7 +156,7 @@ public ToastNotification BuildToastText04(string title, string content, string c
public ToastNotification BuildToastImageAndText01(string image, string content, string arg = null)
{
// build toast
var template = ToastTemplateType.ToastText02;
var template = ToastTemplateType.ToastImageAndText01;
var xml = ToastNotificationManager.GetTemplateContent(template);
var elements = xml.GetElementsByTagName(textNode);

@@ -175,7 +175,7 @@ public ToastNotification BuildToastImageAndText01(string image, string content,
public ToastNotification BuildToastImageAndText02(string image, string title, string content, string arg = null)
{
// build toast
var template = ToastTemplateType.ToastText02;
var template = ToastTemplateType.ToastImageAndText02;
var xml = ToastNotificationManager.GetTemplateContent(template);
var elements = xml.GetElementsByTagName(textNode);

@@ -198,7 +198,7 @@ public ToastNotification BuildToastImageAndText02(string image, string title, st
public ToastNotification BuildToastImageAndText03(string image, string title, string content, string arg = null)
{
// build toast
var template = ToastTemplateType.ToastText03;
var template = ToastTemplateType.ToastImageAndText03;
var xml = ToastNotificationManager.GetTemplateContent(template);
var elements = xml.GetElementsByTagName(textNode);

@@ -221,7 +221,7 @@ public ToastNotification BuildToastImageAndText03(string image, string title, st
public ToastNotification BuildToastImageAndText04(string image, string title, string content, string content2, string arg = null)
{
// build toast
var template = ToastTemplateType.ToastText02;
var template = ToastTemplateType.ToastImageAndText04;
var xml = ToastNotificationManager.GetTemplateContent(template);
var elements = xml.GetElementsByTagName(textNode);

0 comments on commit fd2cece

Please sign in to comment.