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

Merge development #844

Merged
merged 17 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
12 changes: 2 additions & 10 deletions src/Wpf.Ui.SyntaxHighlight/Controls/CodeBlock.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,8 @@
<Thickness x:Key="CodeBlockBorderThemeThickness">1</Thickness>

<Style TargetType="{x:Type syntax:CodeBlock}">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource ControlFillColorDefault}" />
</Setter.Value>
</Setter>
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource TextFillColorPrimary}" />
</Setter.Value>
</Setter>
<Setter Property="Background" Value="{DynamicResource ControlFillColorDefaultBrush}"/>
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}"/>
<Setter Property="Padding" Value="{StaticResource CodeBlockPadding}" />
<Setter Property="BorderBrush" Value="{DynamicResource ControlElevationBorderBrush}" />
<Setter Property="BorderThickness" Value="{StaticResource CodeBlockBorderThemeThickness}" />
Expand Down
1 change: 1 addition & 0 deletions src/Wpf.Ui.Tray/Wpf.Ui.Tray.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<PropertyGroup>
<GeneratePackageOnBuild Condition="'$(Configuration)'=='Release'">true</GeneratePackageOnBuild>
<GenerateDocumentationFile Condition="'$(Configuration)'=='Release'">true</GenerateDocumentationFile>
<DebugType Condition="'$(Configuration)'=='Release'">none</DebugType>
<PackageIcon>wpfui.png</PackageIcon>
</PropertyGroup>

Expand Down
20 changes: 4 additions & 16 deletions src/Wpf.Ui/Controls/Badge/Badge.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--
<!--
This Source Code Form is subject to the terms of the MIT License.
If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
Copyright (C) Leszek Pomianowski and WPF UI Contributors.
Expand All @@ -11,16 +11,8 @@
xmlns:controls="clr-namespace:Wpf.Ui.Controls">

<Style TargetType="{x:Type controls:Badge}">
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource TextFillColorPrimary}" />
</Setter.Value>
</Setter>
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource SystemAccentColorSecondary}" />
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="{DynamicResource BadgeForeground}"/>
<Setter Property="Background" Value="{DynamicResource BadgeBackground}"/>
<!--<Setter Property="BorderBrush" Value="{DynamicResource SystemAccentBrush}" />-->
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Padding" Value="4" />
Expand All @@ -41,11 +33,7 @@
</Border>
<ControlTemplate.Triggers>
<Trigger Property="Appearance" Value="Primary">
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource TextOnAccentFillColorPrimary}" />
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="{DynamicResource BadgeForeground}"/>
</Trigger>
<Trigger Property="Appearance" Value="Transparent">
<Setter Property="BorderBrush" Value="{DynamicResource ControlElevationBorderBrush}" />
Expand Down
7 changes: 2 additions & 5 deletions src/Wpf.Ui/Controls/CardColor/CardColor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@
<TextBlock
Margin="0"
FontSize="{TemplateBinding SubtitleFontSize}"
Text="{TemplateBinding Subtitle}">
<TextBlock.Foreground>
<SolidColorBrush Color="{DynamicResource CardForegroundPressed}" />
</TextBlock.Foreground>
</TextBlock>
Foreground="{DynamicResource CardForegroundPressed}"
Text="{TemplateBinding Subtitle}" />
</StackPanel>
</Border>
</ControlTemplate>
Expand Down
7 changes: 1 addition & 6 deletions src/Wpf.Ui/Controls/ComboBox/ComboBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Wpf.Ui.Controls"
xmlns:converters="clr-namespace:Wpf.Ui.Converters"
xmlns:system="clr-namespace:System;assembly=System.Runtime">

<Thickness x:Key="ComboBoxPadding">10,8,10,8</Thickness>
Expand Down Expand Up @@ -138,11 +137,7 @@
<Setter TargetName="PART_ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource ComboBoxItemForegroundSelected}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource ComboBoxItemForeground}" />
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="{DynamicResource ComboBoxForegroundDisabled}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Expand Down
1 change: 1 addition & 0 deletions src/Wpf.Ui/Controls/Expander/Expander.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
Grid.Column="0"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
TextElement.FontSize="{TemplateBinding FontSize}"
Content="{TemplateBinding Content}" />
<Grid
x:Name="ChevronGrid"
Expand Down
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...");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, there is no need in #DEBUG, because Debug methods has a special attribute

#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;
}
}
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
5 changes: 1 addition & 4 deletions src/Wpf.Ui/Controls/NavigationView/NavigationViewTop.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,11 @@
BorderBrush="{DynamicResource FlyoutBackground}"
BorderThickness="1"
CornerRadius="8"
Background="{DynamicResource FlyoutBorderBrush}"
SnapsToDevicePixels="True">
<Border.RenderTransform>
<TranslateTransform />
</Border.RenderTransform>
<Border.Background>
<SolidColorBrush Color="{DynamicResource FlyoutBorderBrush}" />
</Border.Background>

<Border.Effect>
<DropShadowEffect
BlurRadius="20"
Expand Down
1 change: 1 addition & 0 deletions src/Wpf.Ui/Controls/TextBox/TextBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
Margin="0"
Padding="1,0"
VerticalAlignment="Center"
FontSize="{TemplateBinding FontSize}"
Foreground="{DynamicResource TextControlPlaceholderForeground}"
Text="{TemplateBinding PlaceholderText}" />
</Grid>
Expand Down
1 change: 1 addition & 0 deletions src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
<!-- Main application title -->
<TextBlock
Grid.Column="1"
FontSize="12"
VerticalAlignment="Center"
Text="{TemplateBinding Title}" />
</Grid>
Expand Down
3 changes: 2 additions & 1 deletion src/Wpf.Ui/Controls/ToggleButton/ToggleButton.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"
TextElement.Foreground="{TemplateBinding Foreground}" />
TextElement.Foreground="{TemplateBinding Foreground}"
TextElement.FontSize="{TemplateBinding FontSize}"/>
</Border>
<ControlTemplate.Triggers>
<MultiTrigger>
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
Loading
Loading