Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MasterDetailsView Windows 10X and Two-pane view support #3173

Closed
wants to merge 13 commits into from
Closed
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ Windows 10 Build Number:
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [ ] November 2019 Update (18363)
- [ ] Insider Build (build number: )

App min and target version:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [ ] November 2019 Update (18363)
- [ ] Insider Build (xxxxx)

Device form factor:
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<IsTestProject>$(MSBuildProjectName.Contains('Test'))</IsTestProject>
<IsUwpProject Condition="'$(IsDesignProject)' != 'true'">$(MSBuildProjectName.Contains('Uwp'))</IsUwpProject>
<IsSampleProject>$(MSBuildProjectName.Contains('Sample'))</IsSampleProject>
<DefaultTargetPlatformVersion>17763</DefaultTargetPlatformVersion>
<DefaultTargetPlatformVersion>18362</DefaultTargetPlatformVersion>
<DefaultTargetPlatformMinVersion>16299</DefaultTargetPlatformMinVersion>
<PackageOutputPath>$(MSBuildThisFileDirectory)bin\nupkg</PackageOutputPath>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion GazeInputTest/GazeInputTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<AssemblyName>GazeInputTest</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.17763.0</TargetPlatformVersion>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.18362.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.17134.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
<AppContainerApplication>true</AppContainerApplication>
<ApplicationType>Windows Store</ApplicationType>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformMinVersion>10.0.17134.0</WindowsTargetPlatformMinVersion>
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
<ProjectName>Microsoft.Toolkit.Uwp.Input.GazeInteraction</ProjectName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<NugetTargetMoniker Condition="'$(DesignTimeBuild)' == 'true'">native</NugetTargetMoniker>
<NugetTargetMoniker Condition="'$(DesignTimeBuild)' != 'true'">UAP,Version=v10.0</NugetTargetMoniker>
<PackageTargetFallback>uap10.0</PackageTargetFallback>
<TargetPlatformVersion Condition="'$(TargetPlatformVersion)' == '' ">10.0.17763.0</TargetPlatformVersion>
<TargetPlatformVersion Condition="'$(TargetPlatformVersion)' == '' ">10.0.18362.0</TargetPlatformVersion>
<TargetPlatformMinVersion Condition="'$(TargetPlatformMinVersion)' == '' ">10.0.10240.0</TargetPlatformMinVersion>
<DefineConstants Condition="'$(DisableImplicitFrameworkDefines)' != 'true'">$(DefineConstants);NETFX_CORE;WINDOWS_UWP;WINRT</DefineConstants>
<CopyLocalLockFileAssemblies Condition="'$(CopyLocalLockFileAssemblies)' == ''">false</CopyLocalLockFileAssemblies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
<Version>6.1.0-build.6</Version>
</PackageReference>
<PackageReference Include="Microsoft.UI.Xaml">
<Version>2.2.190917002</Version>
<Version>2.3.200213001</Version>
</PackageReference>
<PackageReference Include="Monaco.Editor">
<Version>0.7.0-alpha</Version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<AssemblyName>Microsoft.Toolkit.Uwp.Samples.BackgroundTasks</AssemblyName>
<DefaultLanguage>fr-FR</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.17763.0</TargetPlatformVersion>
<TargetPlatformVersion>10.0.18362.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.16299.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<Reference Include="System.Xml" />
<Reference Include="Windows, Version=255.255.255.255, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\UnionMetadata\10.0.17763.0\Windows.winmd</HintPath>
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\UnionMetadata\10.0.18362.0\Windows.winmd</HintPath>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
Expand All @@ -73,12 +73,12 @@
<Reference Include="System.Xaml" />
<Reference Include="System.Runtime.WindowsRuntime.UI.Xaml" />
<Reference Include="Windows.Foundation.FoundationContract">
<HintPath>$(ProgramFiles)\Windows Kits\10\References\10.0.17763.0\Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd</HintPath>
<HintPath>$(ProgramFiles)\Windows Kits\10\References\10.0.18362.0\Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd</HintPath>
<Aliases>WindowsRuntime</Aliases>
<Private>False</Private>
</Reference>
<Reference Include="Windows.Foundation.UniversalApiContract">
<HintPath>$(ProgramFiles)\Windows Kits\10\References\10.0.17763.0\Windows.Foundation.UniversalApiContract\7.0.0.0\Windows.Foundation.UniversalApiContract.winmd</HintPath>
<HintPath>$(ProgramFiles)\Windows Kits\10\References\10.0.18362.0\Windows.Foundation.UniversalApiContract\7.0.0.0\Windows.Foundation.UniversalApiContract.winmd</HintPath>
<Aliases>WindowsRuntime</Aliases>
<Private>False</Private>
</Reference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<Reference Include="System.Xml" />
<Reference Include="Windows, Version=255.255.255.255, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\UnionMetadata\10.0.17763.0\Windows.winmd</HintPath>
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\UnionMetadata\10.0.18362.0\Windows.winmd</HintPath>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
Expand All @@ -74,12 +74,12 @@
<Reference Include="System.Xaml" />
<Reference Include="System.Runtime.WindowsRuntime.UI.Xaml" />
<Reference Include="Windows.Foundation.FoundationContract">
<HintPath>$(ProgramFiles)\Windows Kits\10\References\10.0.17763.0\Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd</HintPath>
<HintPath>$(ProgramFiles)\Windows Kits\10\References\10.0.18362.0\Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd</HintPath>
<Aliases>WindowsRuntime</Aliases>
<Private>False</Private>
</Reference>
<Reference Include="Windows.Foundation.UniversalApiContract">
<HintPath>$(ProgramFiles)\Windows Kits\10\References\10.0.17763.0\Windows.Foundation.UniversalApiContract\7.0.0.0\Windows.Foundation.UniversalApiContract.winmd</HintPath>
<HintPath>$(ProgramFiles)\Windows Kits\10\References\10.0.18362.0\Windows.Foundation.UniversalApiContract\7.0.0.0\Windows.Foundation.UniversalApiContract.winmd</HintPath>
<Aliases>WindowsRuntime</Aliases>
<Private>False</Private>
</Reference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum BackButtonBehavior
/// </summary>
/// <remarks>
/// If the back button controlled by <see cref="Windows.UI.Core.SystemNavigationManager"/> is already visible, the <see cref="MasterDetailsView"/> will hook into that button.
/// If the new NavigationView provided by the Windows UI nuget package is used, the <see cref="MasterDetailsView"/> will enable and show that button.
/// If the new NavigationView provided by the Windows UI NuGet package is used, the <see cref="MasterDetailsView"/> will enable and show that button.
/// Otherwise the inline button is used.
/// </remarks>
Automatic,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Reflection;
using Windows.ApplicationModel;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace Microsoft.Toolkit.Uwp.UI.Controls
{
/// <summary>
/// Panel that allows for a Master/Details pattern.
/// </summary>
/// <seealso cref="Windows.UI.Xaml.Controls.ItemsControl" />
public partial class MasterDetailsView
{
private AppViewBackButtonVisibility? _previousSystemBackButtonVisibility;
private bool _previousNavigationViewBackEnabled;

// Int used because the underlying type is an enum, but we don't have access to the enum
private int _previousNavigationViewBackVisibilty;
private Button _inlineBackButton;
private object _navigationView;
private Frame _frame;

/// <summary>
/// Sets the back button visibility based on the current visual state and selected item
/// </summary>
private void SetBackButtonVisibility(MasterDetailsViewState? previousState = null)
{
const int backButtonVisible = 1;

if (DesignMode.DesignModeEnabled)
{
return;
}

if (ViewState == MasterDetailsViewState.Details)
{
if ((BackButtonBehavior == BackButtonBehavior.Inline) && (_inlineBackButton != null))
{
_inlineBackButton.Visibility = Visibility.Visible;
}
else if (BackButtonBehavior == BackButtonBehavior.Automatic)
{
// Continue to support the system back button if it is being used
SystemNavigationManager navigationManager = SystemNavigationManager.GetForCurrentView();
if (navigationManager.AppViewBackButtonVisibility == AppViewBackButtonVisibility.Visible)
{
// Setting this indicates that the system back button is being used
_previousSystemBackButtonVisibility = navigationManager.AppViewBackButtonVisibility;
}
else if ((_inlineBackButton != null) && ((_navigationView == null) || (_frame == null)))
{
// We can only use the new NavigationView if we also have a Frame
// If there is no frame we have to use the inline button
_inlineBackButton.Visibility = Visibility.Visible;
}
else
{
SetNavigationViewBackButtonState(backButtonVisible, true);
}
}
else if (BackButtonBehavior != BackButtonBehavior.Manual)
{
SystemNavigationManager navigationManager = SystemNavigationManager.GetForCurrentView();
_previousSystemBackButtonVisibility = navigationManager.AppViewBackButtonVisibility;

navigationManager.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
}
}
else if (previousState == MasterDetailsViewState.Details)
{
if ((BackButtonBehavior == BackButtonBehavior.Inline) && (_inlineBackButton != null))
{
_inlineBackButton.Visibility = Visibility.Collapsed;
}
else if (BackButtonBehavior == BackButtonBehavior.Automatic)
{
if (!_previousSystemBackButtonVisibility.HasValue)
{
if ((_inlineBackButton != null) && ((_navigationView == null) || (_frame == null)))
{
_inlineBackButton.Visibility = Visibility.Collapsed;
}
else
{
SetNavigationViewBackButtonState(_previousNavigationViewBackVisibilty, _previousNavigationViewBackEnabled);
}
}
}

if (_previousSystemBackButtonVisibility.HasValue)
{
// Make sure we show the back button if the stack can navigate back
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = _previousSystemBackButtonVisibility.Value;
_previousSystemBackButtonVisibility = null;
}
}
}

private void SetNavigationViewBackButtonState(int visible, bool enabled)
{
if (_navigationView == null)
{
return;
}

System.Type navType = _navigationView.GetType();
PropertyInfo visibleProperty = navType.GetProperty("IsBackButtonVisible");
if (visibleProperty != null)
{
_previousNavigationViewBackVisibilty = (int)visibleProperty.GetValue(_navigationView);
visibleProperty.SetValue(_navigationView, visible);
}

PropertyInfo enabledProperty = navType.GetProperty("IsBackEnabled");
if (enabledProperty != null)
{
_previousNavigationViewBackEnabled = (bool)enabledProperty.GetValue(_navigationView);
enabledProperty.SetValue(_navigationView, enabled);
}
}

/// <summary>
/// Closes the details pane if we are in narrow state
/// </summary>
/// <param name="sender">The sender</param>
/// <param name="args">The event args</param>
private void OnFrameNavigating(object sender, NavigatingCancelEventArgs args)
{
if ((args.NavigationMode == NavigationMode.Back) && (ViewState == MasterDetailsViewState.Details))
{
ClearSelectedItem();
args.Cancel = true;
}
}

/// <summary>
/// Closes the details pane if we are in narrow state
/// </summary>
/// <param name="sender">The sender</param>
/// <param name="args">The event args</param>
private void OnBackRequested(object sender, BackRequestedEventArgs args)
{
if (ViewState == MasterDetailsViewState.Details)
{
// let the OnFrameNavigating method handle it if
if (_frame == null || !_frame.CanGoBack)
{
ClearSelectedItem();
}

args.Handled = true;
}
}

private void OnInlineBackButtonClicked(object sender, RoutedEventArgs e)
{
ClearSelectedItem();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand All @@ -19,7 +19,7 @@ public partial class MasterDetailsView
public event SelectionChangedEventHandler SelectionChanged;

/// <summary>
/// Occurs when the view state changes
/// Occurs when the view state changes.
/// </summary>
public event EventHandler<MasterDetailsViewState> ViewStateChanged;

Expand Down
Loading