Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 committed Jul 2, 2021
2 parents 448dff7 + 05ac4ef commit 6e973cd
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/ControlzEx.Showcase/ControlzEx.Showcase.csproj
Expand Up @@ -35,10 +35,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="XamlColorSchemeGenerator" privateAssets="All" includeAssets="build" />
<PackageReference Include="XamlColorSchemeGenerator" PrivateAssets="All" IncludeAssets="build" />
</ItemGroup>

<Target Name="GenerateXamlFiles" BeforeTargets="DispatchToInnerBuilds">
<Target Name="GenerateXamlFiles" BeforeTargets="DispatchToInnerBuilds;PrepareResources;MarkupCompilePass1;MarkupCompilePass2">
<!-- Generate theme files -->
<Message Text="$(XamlColorSchemeGeneratorExecutable)" />
<Exec Command="&quot;$(XamlColorSchemeGeneratorExecutable)&quot;" WorkingDirectory="$(MSBuildProjectDirectory)/Themes/Themes" />
Expand Down
4 changes: 2 additions & 2 deletions src/ControlzEx.Tests/ControlzEx.Tests.csproj
Expand Up @@ -31,7 +31,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="XamlColorSchemeGenerator" privateAssets="All" includeAssets="build" />
<PackageReference Include="XamlColorSchemeGenerator" PrivateAssets="All" IncludeAssets="build" />
</ItemGroup>

<ItemGroup>
Expand All @@ -40,7 +40,7 @@
</EmbeddedResource>
</ItemGroup>

<Target Name="GenerateXamlFiles" BeforeTargets="DispatchToInnerBuilds">
<Target Name="GenerateXamlFiles" BeforeTargets="DispatchToInnerBuilds;PrepareResources;MarkupCompilePass1;MarkupCompilePass2">
<!-- Generate theme files -->
<Message Text="$(XamlColorSchemeGeneratorExecutable)" />
<Exec Command="&quot;$(XamlColorSchemeGeneratorExecutable)&quot;" WorkingDirectory="$(MSBuildProjectDirectory)/Themes/Themes" />
Expand Down
3 changes: 3 additions & 0 deletions src/ControlzEx.sln.DotSettings
Expand Up @@ -37,8 +37,11 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=ControlzEx_002EShowcase_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=ControlzEx_003B_002A_003BGitVersionInformation_003B_002A/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File480D7749291F4B4BAC12DF9115ADE0CD/@KeyIndexDefined">True</s:Boolean>
<s:Double x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File480D7749291F4B4BAC12DF9115ADE0CD/RelativePriority/@EntryValue">1</s:Double>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EdotCover_002EIde_002ECore_002EFilterManagement_002EModel_002ESolutionFilterSettingsManagerMigrateSettings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
Expand Down
Expand Up @@ -888,7 +888,7 @@ private void _UpdateSystemMenu(WindowState? assumeState)
switch (state)
{
case WindowState.Maximized:
NativeMethods.EnableMenuItem(hmenu, SC.RESTORE, MF_ENABLED);
NativeMethods.EnableMenuItem(hmenu, SC.RESTORE, canMaximize ? MF_ENABLED : MF_DISABLED);
NativeMethods.EnableMenuItem(hmenu, SC.MOVE, MF_DISABLED);
NativeMethods.EnableMenuItem(hmenu, SC.SIZE, MF_DISABLED);
NativeMethods.EnableMenuItem(hmenu, SC.MINIMIZE, canMinimize ? MF_ENABLED : MF_DISABLED);
Expand Down
23 changes: 18 additions & 5 deletions src/ControlzEx/Controls/TabControlEx.cs
Expand Up @@ -113,7 +113,6 @@ static TabControlEx()
/// </summary>
public TabControlEx()
{
this.Loaded += this.HandleTabControlExLoaded;
this.Unloaded += this.HandleTabControlExUnloaded;
}

Expand Down Expand Up @@ -144,11 +143,20 @@ public override void OnApplyTemplate()
{
base.OnApplyTemplate();

this.ClearItemsHolder();
var newItemsHolder = this.Template.FindName("PART_ItemsHolder", this) as Panel;
var isDifferentItemsHolder = ReferenceEquals(this.itemsHolder, newItemsHolder) == false;

if (isDifferentItemsHolder)
{
this.ClearItemsHolder();
}

this.itemsHolder = this.Template.FindName("PART_ItemsHolder", this) as Panel;
this.itemsHolder = newItemsHolder;

this.RefreshItemsHolder();
if (isDifferentItemsHolder)
{
this.UpdateSelectedContent();
}
}

/// <inheritdoc />
Expand Down Expand Up @@ -346,11 +354,16 @@ private void RefreshItemsHolder()

private void HandleTabControlExLoaded(object? sender, RoutedEventArgs e)
{
this.RefreshItemsHolder();
this.Loaded -= this.HandleTabControlExLoaded;

this.UpdateSelectedContent();
}

private void HandleTabControlExUnloaded(object? sender, RoutedEventArgs e)
{
this.Loaded -= this.HandleTabControlExLoaded;
this.Loaded += this.HandleTabControlExLoaded;

this.ClearItemsHolder();
}

Expand Down
11 changes: 8 additions & 3 deletions src/ControlzEx/ControlzEx.csproj
Expand Up @@ -42,10 +42,15 @@
<Compile DependentUpon="%(Filename)" SubType="Designer" Update="**\*.xaml$(DefaultLanguageSourceExtension)" />
</ItemGroup>

<PropertyGroup>
<IsBuildingForLegacyFramework>false</IsBuildingForLegacyFramework>
<IsBuildingForLegacyFramework Condition="'$(TargetFramework)' == 'net452' or '$(TargetFramework)' == 'net462'">true</IsBuildingForLegacyFramework>
</PropertyGroup>

<ItemGroup>
<Reference Include="System.Web" Condition="!($(DefineConstants.Contains(NETCOREAPP)) or $(DefineConstants.Contains(NET5_0)))" />
<Reference Include="System.Web.Extensions" Condition="!($(DefineConstants.Contains(NETCOREAPP)) or $(DefineConstants.Contains(NET5_0)))" />
<PackageReference Include="System.Text.Json" Condition="$(DefineConstants.Contains(NETCOREAPP)) or $(DefineConstants.Contains(NET5_0))" />
<Reference Include="System.Web" Condition="'$(IsBuildingForLegacyFramework)' == 'true'" />
<Reference Include="System.Web.Extensions" Condition="'$(IsBuildingForLegacyFramework)' == 'true'" />
<PackageReference Include="System.Text.Json" Condition="'$(IsBuildingForLegacyFramework)' == 'false'" />
</ItemGroup>

<!-- reference includes -->
Expand Down
35 changes: 27 additions & 8 deletions src/ControlzEx/Theming/ThemeManager.cs
Expand Up @@ -481,7 +481,14 @@ public Theme ChangeTheme([NotNull] Application app, [NotNull] string themeName,
throw new ArgumentNullException(nameof(themeName));
}

return this.ChangeTheme(app, app.Resources, this.GetTheme(themeName, highContrast)!);
var theme = this.GetTheme(themeName, highContrast);

if (theme is null)
{
throw new ArgumentException($"Could not find a theme matching \"{themeName}\" and high contrast = \"{highContrast}\".");
}

return this.ChangeTheme(app, app.Resources, theme);
}

/// <summary>
Expand All @@ -500,7 +507,14 @@ public Theme ChangeTheme([NotNull] FrameworkElement frameworkElement, [NotNull]
throw new ArgumentNullException(nameof(themeName));
}

return this.ChangeTheme(frameworkElement, this.GetTheme(themeName, highContrast)!);
var theme = this.GetTheme(themeName, highContrast);

if (theme is null)
{
throw new ArgumentException($"Could not find a theme matching \"{themeName}\" and high contrast = \"{highContrast}\".");
}

return this.ChangeTheme(frameworkElement, theme);
}

/// <summary>
Expand Down Expand Up @@ -1145,7 +1159,7 @@ private bool DetectThemeFromResources(ResourceDictionary dict, out Theme? detect
[SecurityCritical]
private void OnThemeChanged(object? target, ResourceDictionary targetResourceDictionary, Theme? oldTheme, Theme newTheme)
{
this.ThemeChanged?.Invoke(Application.Current, new ThemeChangedEventArgs(target, targetResourceDictionary, oldTheme, newTheme));
this.ThemeChanged?.Invoke(this, new ThemeChangedEventArgs(target, targetResourceDictionary, oldTheme, newTheme));
}

public void SyncTheme()
Expand Down Expand Up @@ -1181,22 +1195,27 @@ public void SyncTheme(ThemeSyncMode? syncMode)
baseColor ??= detectedTheme?.BaseColorScheme ?? BaseColorLight;
}

string? accentColor = null;
string? accentColor;
if (syncModeToUse.HasFlag(ThemeSyncMode.SyncWithAccent))
{
accentColor = WindowsThemeHelper.GetWindowsAccentColor().ToString();
accentColor = WindowsThemeHelper.GetWindowsAccentColor()?.ToString() ?? detectedTheme?.ColorScheme;
}
else
{
// If there was no detected Theme just use the windows accent color.
accentColor ??= detectedTheme?.ColorScheme ?? WindowsThemeHelper.GetWindowsAccentColor().ToString();
accentColor = detectedTheme?.ColorScheme ?? WindowsThemeHelper.GetWindowsAccentColor()?.ToString();
}

if (accentColor is null)
{
throw new Exception("Accent color could not be detected.");
}

var isHighContrast = syncModeToUse.HasFlag(ThemeSyncMode.SyncWithHighContrast)
&& WindowsThemeHelper.IsHighContrastEnabled();

// Check if we previously generated a theme matching the desired settings
var theme = this.GetTheme(baseColor, accentColor!, isHighContrast)
var theme = this.GetTheme(baseColor, accentColor, isHighContrast)
?? RuntimeThemeGenerator.Current.GenerateRuntimeThemeFromWindowsSettings(baseColor, isHighContrast, this.libraryThemeProvidersInternal);

// Only change the theme if it's not the current already
Expand Down Expand Up @@ -1328,4 +1347,4 @@ public enum ThemeSyncMode
SyncAll = SyncWithAppMode | SyncWithAccent | SyncWithHighContrast
}
#pragma warning restore CA1008
}
}
10 changes: 4 additions & 6 deletions src/ControlzEx/Theming/WindowsThemeHelper.cs
Expand Up @@ -86,12 +86,9 @@ public static string GetWindowsBaseColor()
return baseColor;
}

[CanBeNull]
[MustUseReturnValue]
public static Color? GetWindowsAccentColor()
{
Color? accentColor = null;

try
{
var registryValue = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM", "ColorizationColor", null);
Expand All @@ -107,17 +104,18 @@ public static string GetWindowsBaseColor()
if (pp > 0)
{
var bytes = BitConverter.GetBytes(pp);
accentColor = Color.FromArgb(bytes[3], bytes[2], bytes[1], bytes[0]);
// We ignore the alpha value of the color as we always expect it to be fully opaque
return Color.FromRgb(bytes[2], bytes[1], bytes[0]);
}

return accentColor;
return null;
}
catch (Exception exception)
{
Trace.TraceError(exception.ToString());
}

return accentColor;
return null;
}

//public static Color? GetWindowsAccentColorFromUWP()
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Expand Up @@ -36,7 +36,7 @@

<!-- Add the references for all projects and targets -->
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" PrivateAssets="All" includeAssets="build;compile" />
<PackageReference Include="JetBrains.Annotations" PrivateAssets="All" IncludeAssets="build;compile" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" />

<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" IncludeAssets="build;analyzers" Condition="$(DefineConstants.Contains(NETCOREAPP))" />
Expand Down
12 changes: 6 additions & 6 deletions src/Directory.packages.props
@@ -1,6 +1,6 @@
<Project>
<ItemGroup>
<PackageVersion Include="XamlColorSchemeGenerator" version="4.0.0-rc0144" />
<PackageVersion Include="XamlColorSchemeGenerator" Version="4.0.0-rc0155" />
<PackageVersion Include="System.Text.Json" Version="5.0.1" />
<PackageVersion Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.31" />
</ItemGroup>
Expand All @@ -9,15 +9,15 @@
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageVersion Include="NUnit3TestAdapter" Version="3.17" />

<PackageVersion Include="NUnit" version="3.13.1" />
<PackageVersion Include="NUnit" Version="3.13.1" />
</ItemGroup>

<ItemGroup Label="Build">
<PackageVersion Include="JetBrains.Annotations" version="2020.3.0" />
<PackageVersion Include="JetBrains.Annotations" Version="2020.3.0" />

<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" version="3.8.0" />
<PackageVersion Include="StyleCop.Analyzers" version="1.2.0-beta.321" />
<PackageVersion Include="WpfAnalyzers" version="3.5.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.321" />
<PackageVersion Include="WpfAnalyzers" Version="3.5.4" />

<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.0" />
</ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/global.json
@@ -1,5 +1,6 @@
{
"sdk": {
"version": "5.0.103"
"version": "5.0.103",
"rollForward": "latestFeature"
}
}

0 comments on commit 6e973cd

Please sign in to comment.