Skip to content

Commit

Permalink
Merge pull request #843 from lepoco/update/pre11
Browse files Browse the repository at this point in the history
Update/pre11
  • Loading branch information
pomianowski authored Nov 24, 2023
2 parents ada8fcb + ec12b5f commit 68e6ee6
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Version>3.0.0-preview.10</Version>
<Version>3.0.0-preview.11</Version>
<LangVersion>12.0</LangVersion>
<Deterministic>true</Deterministic>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Wpf.Ui.Demo.Mvvm/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

global using System.Windows;
global using CommunityToolkit.Mvvm.ComponentModel;
global using CommunityToolkit.Mvvm.Input;
global using System.Windows;
2 changes: 1 addition & 1 deletion src/Wpf.Ui.Demo.Simple/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<ui:NavigationView.FooterMenuItems>
<ui:NavigationViewItem
Content="Settings"
NavigationCacheMode="Enabled"
NavigationCacheMode="Disabled"
TargetPageType="{x:Type pages:SettingsPage}">
<ui:NavigationViewItem.Icon>
<ui:SymbolIcon Symbol="Settings24" />
Expand Down
6 changes: 3 additions & 3 deletions src/Wpf.Ui.Extension.Template.Compact/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
global using CommunityToolkit.Mvvm.ComponentModel;
global using CommunityToolkit.Mvvm.Input;
global using System;
global using System;
global using System.Windows;
global using CommunityToolkit.Mvvm.ComponentModel;
global using CommunityToolkit.Mvvm.Input;
global using Wpf.Ui.Services;
6 changes: 3 additions & 3 deletions src/Wpf.Ui.Extension.Template.Fluent/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
global using CommunityToolkit.Mvvm.ComponentModel;
global using CommunityToolkit.Mvvm.Input;
global using System;
global using System;
global using System.Windows;
global using CommunityToolkit.Mvvm.ComponentModel;
global using CommunityToolkit.Mvvm.Input;
global using Wpf.Ui.Services;
10 changes: 5 additions & 5 deletions src/Wpf.Ui.Gallery/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

global using CommunityToolkit.Mvvm.ComponentModel;
global using CommunityToolkit.Mvvm.Input;
global using Microsoft.Extensions.Configuration;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Hosting;
global using System;
global using System.Collections.Generic;
global using System.Collections.ObjectModel;
Expand All @@ -25,3 +20,8 @@
global using System.Windows.Markup;
global using System.Windows.Media;
global using System.Windows.Threading;
global using CommunityToolkit.Mvvm.ComponentModel;
global using CommunityToolkit.Mvvm.Input;
global using Microsoft.Extensions.Configuration;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Hosting;
18 changes: 18 additions & 0 deletions src/Wpf.Ui/Controls/NavigationView/NavigationCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,34 @@ internal class NavigationCache

if (cacheMode == NavigationCacheMode.Disabled)
{
#if DEBUG
System
.Diagnostics
.Debug
.WriteLine($"Cache for {entryType} is disabled. Generating instance using action...");
#endif

return generate.Invoke();
}

if (!_entires.TryGetValue(entryType, out var value))
{
#if DEBUG
System
.Diagnostics
.Debug
.WriteLine($"{entryType} not found in cache, generating instance using action...");
#endif

value = generate.Invoke();

_entires.Add(entryType, value);
}

#if DEBUG
System.Diagnostics.Debug.WriteLine($"{entryType} found in cache.");
#endif

return value;
}
}
2 changes: 1 addition & 1 deletion src/Wpf.Ui/Controls/NavigationView/NavigationCacheMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ public enum NavigationCacheMode
/// <summary>
/// The page is cached and the cached instance is reused for every visit regardless of the cache size for the frame.
/// </summary>
Reguired
Required
}
69 changes: 50 additions & 19 deletions src/Wpf.Ui/Controls/NavigationView/NavigationView.Navigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,11 @@ private void AddToJournal(INavigationViewItem viewItem, bool isBackwardsNavigate

#if DEBUG
Debug.WriteLineIf(EnableDebugMessages, $"JOURNAL INDEX {_currentIndexInJournal}");

if (Journal.Count > 0)
{
Debug.WriteLineIf(EnableDebugMessages, $"JOURNAL LAST ELEMENT {Journal[^1]}");
}
#endif
}

Expand All @@ -263,26 +266,54 @@ private object GetNavigationItemInstance(INavigationViewItem viewItem)
?? throw new ArgumentNullException($"{nameof(_pageService.GetPage)} returned null");
}

return NavigationViewActivator.CreateInstance(viewItem.TargetPageType)
?? throw new ArgumentException("Failed to create instance of the page");
return _cache.Remember(
viewItem.TargetPageType,
viewItem.NavigationCacheMode,
ComputeCachedNavigationInstance
)
?? throw new ArgumentNullException(
$"Unable to get or create instance of {viewItem.TargetPageType} from cache."
);

//return _cache.Remember(viewItem.TargetPageType, viewItem.NavigationCacheMode, () =>
//{
// if (_serviceProvider is not null)
// {
// return _serviceProvider.GetService(viewItem.TargetPageType) ??
// new ArgumentNullException($"{nameof(_serviceProvider.GetService)} returned null");
// }

// if (_pageService is not null)
// {
// return _pageService.GetPage(viewItem.TargetPageType) ??
// throw new ArgumentNullException($"{nameof(_pageService.GetPage)} returned null");
// }

// return NavigationViewActivator.CreateInstance(viewItem.TargetPageType) ??
// throw new ArgumentException("Failed to create instance of the page");
//});
object? ComputeCachedNavigationInstance() => GetPageInstanceFromCache(viewItem.TargetPageType);
}

private object? GetPageInstanceFromCache(Type? targetPageType)
{
if (targetPageType is null)
{
return default;
}

if (_serviceProvider is not null)
{
#if DEBUG
System
.Diagnostics
.Debug
.WriteLine($"Getting {targetPageType} from cache using IServiceProvider.");
#endif

return _serviceProvider.GetService(targetPageType)
?? new ArgumentNullException($"{nameof(_serviceProvider.GetService)} returned null");
}

if (_pageService is not null)
{
#if DEBUG
System.Diagnostics.Debug.WriteLine($"Getting {targetPageType} from cache using IPageService.");
#endif

return _pageService.GetPage(targetPageType)
?? throw new ArgumentNullException($"{nameof(_pageService.GetPage)} returned null");
}

#if DEBUG
System.Diagnostics.Debug.WriteLine($"Getting {targetPageType} from cache using reflection.");
#endif

return NavigationViewActivator.CreateInstance(targetPageType)
?? throw new ArgumentException("Failed to create instance of the page");
}

private static void ApplyAttachedProperties(INavigationViewItem viewItem, object pageInstance)
Expand Down
10 changes: 5 additions & 5 deletions src/Wpf.Ui/Interop/UnsafeNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,11 @@ public static bool ApplyWindowLegacyMicaEffect(IntPtr handle)

// TODO: Validate HRESULT
_ = Dwmapi.DwmSetWindowAttribute(
handle,
Dwmapi.DWMWINDOWATTRIBUTE.DWMWA_MICA_EFFECT,
ref backdropPvAttribute,
Marshal.SizeOf(typeof(int))
);
handle,
Dwmapi.DWMWINDOWATTRIBUTE.DWMWA_MICA_EFFECT,
ref backdropPvAttribute,
Marshal.SizeOf(typeof(int))
);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Wpf.Ui.UnitTests/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

global using NSubstitute;
global using System;
global using System.Windows;
global using NSubstitute;
global using Xunit;

0 comments on commit 68e6ee6

Please sign in to comment.