clean up a bit
This commit is contained in:
Родитель
c6d30abf35
Коммит
d325ec7367
|
@ -11,7 +11,7 @@
|
||||||
<AssemblyName>Microsoft.Toolkit.Uwp.SampleApp</AssemblyName>
|
<AssemblyName>Microsoft.Toolkit.Uwp.SampleApp</AssemblyName>
|
||||||
<DefaultLanguage>en-US</DefaultLanguage>
|
<DefaultLanguage>en-US</DefaultLanguage>
|
||||||
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
|
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
|
||||||
<TargetPlatformVersion>10.0.16299.0</TargetPlatformVersion>
|
<TargetPlatformVersion>10.0.15063.0</TargetPlatformVersion>
|
||||||
<TargetPlatformMinVersion>10.0.14393.0</TargetPlatformMinVersion>
|
<TargetPlatformMinVersion>10.0.14393.0</TargetPlatformMinVersion>
|
||||||
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
|
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
<AssemblyName>Microsoft.Toolkit.Uwp.Samples.BackgroundTasks</AssemblyName>
|
<AssemblyName>Microsoft.Toolkit.Uwp.Samples.BackgroundTasks</AssemblyName>
|
||||||
<DefaultLanguage>fr-FR</DefaultLanguage>
|
<DefaultLanguage>fr-FR</DefaultLanguage>
|
||||||
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
|
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
|
||||||
<TargetPlatformVersion>10.0.15063.0</TargetPlatformVersion>
|
<TargetPlatformVersion>10.0.16299.0</TargetPlatformVersion>
|
||||||
<TargetPlatformMinVersion>10.0.14393.0</TargetPlatformMinVersion>
|
<TargetPlatformMinVersion>10.0.14393.0</TargetPlatformMinVersion>
|
||||||
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
|
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
|
|
|
@ -36,23 +36,23 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
|
||||||
|
|
||||||
private ControlTemplate _previousTemplateUsed;
|
private ControlTemplate _previousTemplateUsed;
|
||||||
|
|
||||||
private NavigationView _navigationView;
|
private object _navigationView;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <see cref="NavigationView"/>. Returns null when device does not support
|
/// Gets the <see cref="NavigationView"/>. Returns null when device does not support
|
||||||
/// NavigationView or when <see cref="UseNavigationViewWhenPossible"/> is set to false
|
/// NavigationView or when <see cref="UseNavigationViewWhenPossible"/> is set to false
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public NavigationView NavigationView
|
//public NavigationView NavigationView
|
||||||
{
|
//{
|
||||||
get { return _navigationView; }
|
// get { return _navigationView; }
|
||||||
}
|
//}
|
||||||
|
|
||||||
private bool UsingNavView => UseNavigationViewWhenPossible && IsNavViewSupported;
|
private bool UsingNavView => UseNavigationViewWhenPossible && IsNavigationViewSupported;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether <see cref="NavigationView"/> is supported
|
/// Gets a value indicating whether <see cref="NavigationView"/> is supported
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool IsNavViewSupported => (bool)(_isNavViewSupported ??
|
public static bool IsNavigationViewSupported => (bool)(_isNavViewSupported ??
|
||||||
(_isNavViewSupported = ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5)));
|
(_isNavViewSupported = ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5)));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -88,11 +88,11 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
|
||||||
_optionsListView.ItemClick -= OptionsListView_ItemClick;
|
_optionsListView.ItemClick -= OptionsListView_ItemClick;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UsingNavView && _navigationView != null)
|
if (UsingNavView && _navigationView is NavigationView navView && navView != null)
|
||||||
{
|
{
|
||||||
_navigationView.ItemInvoked -= NavigationViewItemInvoked;
|
navView.ItemInvoked -= NavigationViewItemInvoked;
|
||||||
_navigationView.SelectionChanged -= NavigationViewSelectionChanged;
|
navView.SelectionChanged -= NavigationViewSelectionChanged;
|
||||||
_navigationView.Loaded -= NavigationViewLoaded;
|
navView.Loaded -= NavigationViewLoaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
_hamburgerButton = (Button)GetTemplateChild("HamburgerButton");
|
_hamburgerButton = (Button)GetTemplateChild("HamburgerButton");
|
||||||
|
@ -101,16 +101,18 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
|
||||||
|
|
||||||
if (UsingNavView)
|
if (UsingNavView)
|
||||||
{
|
{
|
||||||
_navigationView = (NavigationView)GetTemplateChild("NavView");
|
var _navView = (NavigationView)GetTemplateChild("NavView");
|
||||||
|
|
||||||
if (_navigationView != null)
|
if (_navView != null)
|
||||||
{
|
{
|
||||||
_navigationView.ItemInvoked += NavigationViewItemInvoked;
|
_navView.ItemInvoked += NavigationViewItemInvoked;
|
||||||
_navigationView.SelectionChanged += NavigationViewSelectionChanged;
|
_navView.SelectionChanged += NavigationViewSelectionChanged;
|
||||||
_navigationView.Loaded += NavigationViewLoaded;
|
_navView.Loaded += NavigationViewLoaded;
|
||||||
_navigationView.MenuItemTemplateSelector = new HamburgerMenuNavViewItemTemplateSelector(this);
|
_navView.MenuItemTemplateSelector = new HamburgerMenuNavViewItemTemplateSelector(this);
|
||||||
|
|
||||||
OnItemsSourceChanged(this, null);
|
OnItemsSourceChanged(this, null);
|
||||||
|
|
||||||
|
_navigationView = _navView;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +138,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
|
||||||
{
|
{
|
||||||
var hm = d as HamburgerMenu;
|
var hm = d as HamburgerMenu;
|
||||||
|
|
||||||
if (hm.UsingNavView && hm._navigationView != null)
|
if (hm.UsingNavView && hm._navigationView is NavigationView navView && navView != null)
|
||||||
{
|
{
|
||||||
var items = hm.ItemsSource as IEnumerable<object>;
|
var items = hm.ItemsSource as IEnumerable<object>;
|
||||||
var options = hm.OptionsItemsSource as IEnumerable<object>;
|
var options = hm.OptionsItemsSource as IEnumerable<object>;
|
||||||
|
@ -164,7 +166,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hm._navigationView.MenuItemsSource = combined;
|
navView.MenuItemsSource = combined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +174,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
|
||||||
{
|
{
|
||||||
var menu = d as HamburgerMenu;
|
var menu = d as HamburgerMenu;
|
||||||
|
|
||||||
if (menu.UseNavigationViewWhenPossible && HamburgerMenu.IsNavViewSupported)
|
if (menu.UseNavigationViewWhenPossible && HamburgerMenu.IsNavigationViewSupported)
|
||||||
{
|
{
|
||||||
ResourceDictionary dict = new ResourceDictionary();
|
ResourceDictionary dict = new ResourceDictionary();
|
||||||
dict.Source = new System.Uri("ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls/Themes/Generic.xaml");
|
dict.Source = new System.Uri("ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls/Themes/Generic.xaml");
|
||||||
|
@ -191,21 +193,21 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
|
||||||
private static void OnSelectedItemChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
private static void OnSelectedItemChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
var menu = d as HamburgerMenu;
|
var menu = d as HamburgerMenu;
|
||||||
if (menu.UsingNavView)
|
if (menu.UsingNavView && menu._navigationView is NavigationView navView)
|
||||||
{
|
{
|
||||||
menu._navigationView.SelectedItem = e.NewValue;
|
navView.SelectedItem = e.NewValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnSelectedIndexChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
private static void OnSelectedIndexChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
var menu = d as HamburgerMenu;
|
var menu = d as HamburgerMenu;
|
||||||
if (menu.UsingNavView)
|
if (menu.UsingNavView && menu._navigationView is NavigationView navView)
|
||||||
{
|
{
|
||||||
var items = menu.ItemsSource as IEnumerable<object>;
|
var items = menu.ItemsSource as IEnumerable<object>;
|
||||||
if (items != null)
|
if (items != null)
|
||||||
{
|
{
|
||||||
menu._navigationView.SelectedItem = (int)e.NewValue >= 0 ? items.ElementAt((int)e.NewValue) : null;
|
navView.SelectedItem = (int)e.NewValue >= 0 ? items.ElementAt((int)e.NewValue) : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,20 +215,21 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
|
||||||
private static void OnSelectedOptionsIndexChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
private static void OnSelectedOptionsIndexChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
var menu = d as HamburgerMenu;
|
var menu = d as HamburgerMenu;
|
||||||
if (menu.UsingNavView)
|
if (menu.UsingNavView && menu._navigationView is NavigationView navView)
|
||||||
{
|
{
|
||||||
var options = menu.ItemsSource as IEnumerable<object>;
|
var options = menu.ItemsSource as IEnumerable<object>;
|
||||||
if (options != null)
|
if (options != null)
|
||||||
{
|
{
|
||||||
menu._navigationView.SelectedItem = (int)e.NewValue >= 0 ? options.ElementAt((int)e.NewValue) : null;
|
navView.SelectedItem = (int)e.NewValue >= 0 ? options.ElementAt((int)e.NewValue) : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void NavigationViewLoaded(object sender, RoutedEventArgs e)
|
private void NavigationViewLoaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
_navigationView.Loaded -= NavigationViewLoaded;
|
var navView = sender as NavigationView;
|
||||||
var hamburgerButton = _navigationView.FindDescendantByName("TogglePaneButton") as Button;
|
navView.Loaded -= NavigationViewLoaded;
|
||||||
|
var hamburgerButton = navView.FindDescendantByName("TogglePaneButton") as Button;
|
||||||
|
|
||||||
if (hamburgerButton != null)
|
if (hamburgerButton != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,16 @@
|
||||||
using System;
|
// ******************************************************************
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// This code is licensed under the MIT License (MIT).
|
||||||
|
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||||
|
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
|
||||||
|
// ******************************************************************
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
|
@ -1,4 +1,16 @@
|
||||||
using System;
|
// ******************************************************************
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// This code is licensed under the MIT License (MIT).
|
||||||
|
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||||
|
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
|
||||||
|
// ******************************************************************
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
|
@ -1,4 +1,16 @@
|
||||||
using System;
|
// ******************************************************************
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// This code is licensed under the MIT License (MIT).
|
||||||
|
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||||
|
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
|
||||||
|
// ******************************************************************
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Microsoft.Toolkit.Uwp.UI.Controls
|
namespace Microsoft.Toolkit.Uwp.UI.Controls
|
||||||
{
|
{
|
||||||
|
|
Загрузка…
Ссылка в новой задаче