Skip to content

Commit

Permalink
Added the MasterDetailFrame control
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrolamas committed Oct 9, 2016
1 parent 9a79f6a commit f9642d1
Show file tree
Hide file tree
Showing 15 changed files with 546 additions and 82 deletions.
3 changes: 3 additions & 0 deletions src/Cimbalino.Toolkit (UWP)/Cimbalino.Toolkit (UWP).csproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@
<Compile Include="..\cimbalino.toolkit %28wp8%29\controls\ExtendedPageBase.cs">
<Link>Controls\ExtendedPageBase.cs</Link>
</Compile>
<Compile Include="..\Cimbalino.Toolkit %28WP8%29\Controls\IMasterDetailFrame.cs">
<Link>Controls\IMasterDetailFrame.cs</Link>
</Compile>
<Compile Include="..\cimbalino.toolkit %28wp8%29\converters\BooleanToBrushConverter.cs">
<Link>Converters\BooleanToBrushConverter.cs</Link>
</Compile>
Expand Down
1 change: 1 addition & 0 deletions src/Cimbalino.Toolkit (WP8)/Cimbalino.Toolkit (WP8).csproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
<Compile Include="Behaviors\UpdatePasswordBindingOnPropertyChanged.cs" />
<Compile Include="Behaviors\UpdateTextBindingOnPropertyChanged.cs" />
<Compile Include="Controls\ExtendedPageBase.cs" />
<Compile Include="Controls\IMasterDetailFrame.cs" />
<Compile Include="Converters\BooleanToBrushConverter.cs" />
<Compile Include="Converters\BooleanToIntConverter.cs" />
<Compile Include="Converters\BooleanToObjectConverter.cs" />
Expand Down
28 changes: 28 additions & 0 deletions src/Cimbalino.Toolkit (WP8)/Controls/IMasterDetailFrame.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// ****************************************************************************
// <copyright file="IMasterDetailFrame.cs" company="Pedro Lamas">
// Copyright © Pedro Lamas 2014
// </copyright>
// ****************************************************************************
// <author>Pedro Lamas</author>
// <email>[email protected]</email>
// <project>Cimbalino.Toolkit</project>
// <web>http://www.pedrolamas.com</web>
// <license>
// See license.txt in this solution or http://www.pedrolamas.com/license_MIT.txt
// </license>
// ****************************************************************************

namespace Cimbalino.Toolkit.Controls
{
/// <summary>
/// Represents the basic operations for the MasterDetail control.
/// </summary>
public interface IMasterDetailFrame
{
/// <summary>
/// Called when the user presses the hardware back button.
/// </summary>
/// <returns>true if the back button press has been handled; otherwise, false.</returns>
bool HandleBackKeyPress();
}
}
42 changes: 42 additions & 0 deletions src/Cimbalino.Toolkit (WP8)/Services/NavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,48 @@ public virtual bool Navigate(Type type, object parameter)
return ExceptionHelper.ThrowNotSupported<bool>();
}

/// <summary>
/// Navigates the detail frame to the content specified by the type reference.
/// </summary>
/// <typeparam name="T">The page to navigate to, specified as a type reference to its partial class type.</typeparam>
/// <returns>true if navigation is not canceled; otherwise, false.</returns>
public bool NavigateDetail<T>()
{
return ExceptionHelper.ThrowNotSupported<bool>();
}

/// <summary>
/// Navigates the detail frame to the content specified by the type reference.
/// </summary>
/// <typeparam name="T">The page to navigate to, specified as a type reference to its partial class type.</typeparam>
/// <param name="parameter">The navigation parameter to pass to the target page; must have a basic type (string, char, numeric, or GUID).</param>
/// <returns>true if navigation is not canceled; otherwise, false.</returns>
public bool NavigateDetail<T>(object parameter)
{
return ExceptionHelper.ThrowNotSupported<bool>();
}

/// <summary>
/// Navigates the detail frame to the content specified by the type reference.
/// </summary>
/// <param name="type">The page to navigate to, specified as a type reference to its partial class type.</param>
/// <returns>true if navigation is not canceled; otherwise, false.</returns>
public bool NavigateDetail(Type type)
{
return ExceptionHelper.ThrowNotSupported<bool>();
}

/// <summary>
/// Navigates the detail frame to the content specified by the type reference.
/// </summary>
/// <param name="type">The page to navigate to, specified as a type reference to its partial class type.</param>
/// <param name="parameter">The navigation parameter to pass to the target page; must have a basic type (string, char, numeric, or GUID).</param>
/// <returns>true if navigation is not canceled; otherwise, false.</returns>
public bool NavigateDetail(Type type, object parameter)
{
return ExceptionHelper.ThrowNotSupported<bool>();
}

/// <summary>
/// Gets a value indicating whether there is at least one entry in back navigation history.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions src/Cimbalino.Toolkit (WP81)/Cimbalino.Toolkit (WP81).csproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@
<Compile Include="..\Cimbalino.Toolkit %28WP8%29\Controls\ExtendedPageBase.cs">
<Link>Controls\ExtendedPageBase.cs</Link>
</Compile>
<Compile Include="..\Cimbalino.Toolkit %28WP8%29\Controls\IMasterDetailFrame.cs">
<Link>Controls\IMasterDetailFrame.cs</Link>
</Compile>
<Compile Include="..\Cimbalino.Toolkit %28WP8%29\Converters\BooleanToBrushConverter.cs">
<Link>Converters\BooleanToBrushConverter.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@
<Compile Include="..\cimbalino.toolkit %28wp8%29\controls\ExtendedPageBase.cs">
<Link>Controls\ExtendedPageBase.cs</Link>
</Compile>
<Compile Include="..\Cimbalino.Toolkit %28WP8%29\Controls\IMasterDetailFrame.cs">
<Link>Controls\IMasterDetailFrame.cs</Link>
</Compile>
<Compile Include="..\Cimbalino.Toolkit %28WP8%29\Converters\BooleanToBrushConverter.cs">
<Link>Converters\BooleanToBrushConverter.cs</Link>
</Compile>
Expand Down
126 changes: 103 additions & 23 deletions src/Cimbalino.Toolkit (WPA81)/Services/NavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#if WINDOWS_PHONE_APP
using System;
using System.Collections.Generic;
using System.Linq;
using Cimbalino.Toolkit.Controls;
using Cimbalino.Toolkit.Extensions;
using Cimbalino.Toolkit.Helpers;
using Windows.Phone.UI.Input;
Expand All @@ -23,6 +25,8 @@
#elif WINDOWS_UWP
using System;
using System.Collections.Generic;
using System.Linq;
using Cimbalino.Toolkit.Controls;
using Cimbalino.Toolkit.Extensions;
using Cimbalino.Toolkit.Helpers;
using Windows.Phone.UI.Input;
Expand All @@ -32,6 +36,7 @@
#else
using System;
using System.Collections.Generic;
using System.Linq;
using Cimbalino.Toolkit.Extensions;
using Cimbalino.Toolkit.Helpers;
using Windows.UI.Xaml;
Expand Down Expand Up @@ -204,6 +209,48 @@ public virtual bool Navigate(Type type, object parameter)
return GetFrame()?.Navigate(type, parameter) ?? false;
}

/// <summary>
/// Navigates the detail frame to the content specified by the type reference.
/// </summary>
/// <typeparam name="T">The page to navigate to, specified as a type reference to its partial class type.</typeparam>
/// <returns>true if navigation is not canceled; otherwise, false.</returns>
public bool NavigateDetail<T>()
{
return Navigate(typeof(T));
}

/// <summary>
/// Navigates the detail frame to the content specified by the type reference.
/// </summary>
/// <typeparam name="T">The page to navigate to, specified as a type reference to its partial class type.</typeparam>
/// <param name="parameter">The navigation parameter to pass to the target page; must have a basic type (string, char, numeric, or GUID).</param>
/// <returns>true if navigation is not canceled; otherwise, false.</returns>
public bool NavigateDetail<T>(object parameter)
{
return Navigate(typeof(T), parameter);
}

/// <summary>
/// Navigates the detail frame to the content specified by the type reference.
/// </summary>
/// <param name="type">The page to navigate to, specified as a type reference to its partial class type.</param>
/// <returns>true if navigation is not canceled; otherwise, false.</returns>
public bool NavigateDetail(Type type)
{
return GetDetailFrame()?.Navigate(type) ?? false;
}

/// <summary>
/// Navigates the detail frame to the content specified by the type reference.
/// </summary>
/// <param name="type">The page to navigate to, specified as a type reference to its partial class type.</param>
/// <param name="parameter">The navigation parameter to pass to the target page; must have a basic type (string, char, numeric, or GUID).</param>
/// <returns>true if navigation is not canceled; otherwise, false.</returns>
public bool NavigateDetail(Type type, object parameter)
{
return GetDetailFrame()?.Navigate(type, parameter) ?? false;
}

/// <summary>
/// Gets a value indicating whether there is at least one entry in back navigation history.
/// </summary>
Expand Down Expand Up @@ -332,6 +379,20 @@ private Frame GetFrame()
return frame;
}

private Frame GetDetailFrame()
{
var detailFrame = (Frame)null;

var page = GetFrame()?.Content as Page;

if (page != null)
{
detailFrame = page.GetVisualDescendents<Frame>().FirstOrDefault();
}

return detailFrame;
}

private void Frame_Navigated(object sender, Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
CurrentParameter = e.Parameter;
Expand Down Expand Up @@ -386,38 +447,57 @@ private void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)

private bool HandleBackKeyPress()
{
var handled = false;
var handled = (GetDetailFrame() as IMasterDetailFrame)?.HandleBackKeyPress() ?? false;

var eventArgs = new NavigationServiceBackKeyPressedEventArgs();
if (!handled)
{
var eventArgs = new NavigationServiceBackKeyPressedEventArgs();

RaiseBackKeyPressed(eventArgs);
RaiseBackKeyPressed(eventArgs);

switch (eventArgs.Behavior)
{
case NavigationServiceBackKeyPressedBehavior.GoBack:
var frame = GetFrame();
switch (eventArgs.Behavior)
{
case NavigationServiceBackKeyPressedBehavior.GoBack:
var frame = GetFrame();

if (frame?.CanGoBack ?? false)
{
frame.GoBack();
handled = true;
}
break;

if (frame?.CanGoBack ?? false)
{
frame.GoBack();
case NavigationServiceBackKeyPressedBehavior.HideApp:
break;

case NavigationServiceBackKeyPressedBehavior.ExitApp:
handled = true;
}
break;
Application.Current?.Exit();
break;

case NavigationServiceBackKeyPressedBehavior.DoNothing:
handled = true;
break;

default:
throw new ArgumentOutOfRangeException();
}
}

case NavigationServiceBackKeyPressedBehavior.HideApp:
break;
return handled;
}

case NavigationServiceBackKeyPressedBehavior.ExitApp:
handled = true;
Application.Current?.Exit();
break;
private bool HandleDetailBackKeyPress()
{
var handled = false;

var detailFrame = GetDetailFrame();

case NavigationServiceBackKeyPressedBehavior.DoNothing:
handled = true;
break;
if (detailFrame != null && detailFrame.CanGoBack)
{
detailFrame.GoBack();

default:
throw new ArgumentOutOfRangeException();
handled = true;
}

return handled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@
<Compile Include="..\cimbalino.toolkit %28wp8%29\controls\ExtendedPageBase.cs">
<Link>Controls\ExtendedPageBase.cs</Link>
</Compile>
<Compile Include="..\Cimbalino.Toolkit %28WP8%29\Controls\IMasterDetailFrame.cs">
<Link>Controls\IMasterDetailFrame.cs</Link>
</Compile>
<Compile Include="..\Cimbalino.Toolkit %28WP8%29\Converters\BooleanToBrushConverter.cs">
<Link>Converters\BooleanToBrushConverter.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
<Compile Include="Controls\HamburgerMenuButton.cs" />
<Compile Include="Controls\HamburgerFrame.cs" />
<Compile Include="Controls\HamburgerTitleBar.cs" />
<Compile Include="Controls\MasterDetailFrame.cs" />
<Compile Include="Controls\MasterDetailFrameDisplayMode.cs" />
<Compile Include="Helpers\Hamburger.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Properties\Cimbalino.Toolkit.Controls.rd.xml" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public Type NavigationSourcePageType
/// The navigation parameter property
/// </summary>
public static readonly DependencyProperty NavigationParameterProperty = DependencyProperty.Register(
nameof(NavigationParameter), typeof(object), typeof(HamburgerMenuButton), new PropertyMetadata(default(object)));
nameof(NavigationParameter), typeof(object), typeof(HamburgerMenuButton), new PropertyMetadata(null));

/// <summary>
/// Gets or sets the navigation parameter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected override void OnApplyTemplate()

base.OnApplyTemplate();

_menuButton = (Button)GetTemplateChild("MenuButton");
_menuButton = (Button)this.GetTemplateChild("MenuButton");

if (_menuButton != null)
{
Expand Down
Loading

0 comments on commit f9642d1

Please sign in to comment.