Skip to content

Commit

Permalink
Merge pull request #4300 from batzen/features/ControlzEx6
Browse files Browse the repository at this point in the history
Update ControlzEx to version 6.0
  • Loading branch information
batzen authored Aug 17, 2022
2 parents 05906a2 + 32e0430 commit 8f28aba
Show file tree
Hide file tree
Showing 27 changed files with 358 additions and 384 deletions.
10 changes: 10 additions & 0 deletions src/Directory.Build.Targets
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,14 @@
<Page Update="@(Page)" SubType="Designer" Generator="MSBuild:Compile" />
</ItemGroup>

<Target Name="RemoveDuplicateAnalyzers" BeforeTargets="CoreCompile">
<!-- Work around https://github.com/dotnet/wpf/issues/6792 -->

<ItemGroup>
<FilteredAnalyzer Include="@(Analyzer->Distinct())" />
<Analyzer Remove="@(Analyzer)" />
<Analyzer Include="@(FilteredAnalyzer)" />
</ItemGroup>
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Title="CleanWindowDemo"
Width="800"
Height="400"
GlowBrush="{DynamicResource MahApps.Brushes.Accent}"
GlowColor="{DynamicResource MahApps.Colors.Accent}"
Icon="..\mahapps.metro.logo2.ico"
ResizeMode="CanResizeWithGrip"
ShowIconOnTitleBar="True"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
Title="SizeToContent Demo"
GlowBrush="{DynamicResource MahApps.Brushes.Accent}"
GlowColor="{DynamicResource MahApps.Colors.Accent}"
SizeToContent="WidthAndHeight"
WindowStartupLocation="CenterOwner">
<Grid Width="50"
Expand Down
43 changes: 37 additions & 6 deletions src/MahApps.Metro.Samples/MahApps.Metro.Demo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
xmlns:local="clr-namespace:MetroDemo"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:theming="urn:controlzex"
xmlns:controlzEx="urn:controlzex"
Title="MahApps.Metro - Demo Application"
Width="1024"
Height="768"
Expand All @@ -18,9 +18,9 @@
d:DesignWidth="800"
mah:DialogParticipation.Register="{Binding}"
Closing="MetroWindow_Closing"
GlowBrush="{DynamicResource MahApps.Brushes.Accent}"
GlowColor="{DynamicResource MahApps.Colors.Accent}"
Icon="mahapps.metro.logo2.ico"
NonActiveGlowBrush="#CDFF0000"
NonActiveGlowColor="#CDFF0000"
ResizeMode="CanResizeWithGrip"
ShowIconOnTitleBar="True"
WindowStartupLocation="CenterScreen"
Expand All @@ -37,9 +37,9 @@
<ResourceDictionary>
<ObjectDataProvider x:Key="SyncModePreferenceEnumValues"
MethodName="GetValues"
ObjectType="{x:Type theming:ThemeSyncMode}">
ObjectType="{x:Type controlzEx:ThemeSyncMode}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="theming:ThemeSyncMode" />
<x:Type TypeName="controlzEx:ThemeSyncMode" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>

Expand Down Expand Up @@ -106,6 +106,14 @@
Style="{DynamicResource MahApps.Styles.Button.Dialogs}" />
</StackPanel>
</UserControl>

<ObjectDataProvider x:Key="CornerPreferenceEnumValues"
MethodName="GetValues"
ObjectType="{x:Type controlzEx:WindowCornerPreference}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="controlzEx:WindowCornerPreference" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</ResourceDictionary>
</Window.Resources>

Expand Down Expand Up @@ -168,7 +176,7 @@
ItemsSource="{Binding Source={StaticResource SyncModePreferenceEnumValues}}" />
<MenuItem Header="Use HSL colors?"
IsCheckable="True"
IsChecked="{Binding Options.UseHSL, Source={x:Static theming:RuntimeThemeGenerator.Current}, Mode=TwoWay}" />
IsChecked="{Binding Options.UseHSL, Source={x:Static controlzEx:RuntimeThemeGenerator.Current}, Mode=TwoWay}" />

<MenuItem Command="{Binding DataContext.SyncThemeNowCommand, RelativeSource={RelativeSource AncestorType=Window}}" Header="Sync now" />
</MenuItem>
Expand Down Expand Up @@ -218,6 +226,29 @@
<MenuItem Command="{Binding ShowCustomDialogCommand}" Header="Show CustomDialog via VM" />
</MenuItem>
<MenuItem Header="Window">
<MenuItem Header="Chrome">
<MenuItem>
<MenuItem.Template>
<ControlTemplate>
<StackPanel Orientation="Horizontal">
<Label Content="CornerPreference" />
<ComboBox VerticalAlignment="Center"
ItemsSource="{Binding Source={StaticResource CornerPreferenceEnumValues}}"
SelectedItem="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mah:MetroWindow}}, Path=CornerPreference, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
</ControlTemplate>
</MenuItem.Template>
</MenuItem>
</MenuItem>
<MenuItem Header="Glow">
<MenuItem Header="PreferDWMBorderColor"
IsCheckable="True"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mah:MetroWindow}}, Path=PreferDWMBorderColor}" />
<MenuItem Header="DWMSupportsBorderColor"
IsEnabled="False"
IsCheckable="True"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mah:MetroWindow}}, Path=DWMSupportsBorderColor}" />
</MenuItem>
<MenuItem Header="ShowTitleBar"
IsCheckable="True"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mah:MetroWindow}}, Path=ShowTitleBar}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ private void MenuWindowWithBorderOnClick(object sender, RoutedEventArgs e)
{
var w = this.GetTestWindow();
w.Content = new TextBlock { Text = "MetroWindow with Border", FontSize = 28, FontWeight = FontWeights.Light, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center };
w.GlowColor = null;
w.NonActiveGlowColor = null;
w.Show();
}

Expand All @@ -595,7 +597,7 @@ private void MenuWindowWithGlowOnClick(object sender, RoutedEventArgs e)
w.Content = new Button { Content = "MetroWindow with Glow", ToolTip = "And test tool tip", FontSize = 28, FontWeight = FontWeights.Light, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center };
w.BorderThickness = new Thickness(1);
w.BorderBrush = null;
w.SetResourceReference(GlowBrushProperty, "MahApps.Brushes.Accent");
w.SetResourceReference(GlowColorProperty, "MahApps.Colors.Accent");
w.Show();
}

Expand All @@ -605,7 +607,7 @@ private void MenuWindowWithShadowOnClick(object sender, RoutedEventArgs e)
w.Content = new TextBlock { Text = "Window with drop shadow", FontSize = 28, FontWeight = FontWeights.Light, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center };
w.BorderThickness = new Thickness(0);
w.BorderBrush = null;
w.GlowBrush = Brushes.Black;
w.GlowColor = Colors.Black;
w.Show();
}
}
Expand Down
52 changes: 0 additions & 52 deletions src/MahApps.Metro/Behaviors/BorderlessWindowBehavior.cs

This file was deleted.

54 changes: 37 additions & 17 deletions src/MahApps.Metro/Behaviors/WindowsSettingBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using ControlzEx.Native;
using ControlzEx.Standard;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.Graphics.Gdi;
using Windows.Win32.UI.WindowsAndMessaging;
using MahApps.Metro.Controls;
using Microsoft.Xaml.Behaviors;

Expand Down Expand Up @@ -108,7 +111,6 @@ private void CleanUp(string fromWhere)
});
}

#pragma warning disable 618
private void LoadWindowState()
{
var window = this.AssociatedObject;
Expand Down Expand Up @@ -141,7 +143,7 @@ private void LoadWindowState()

try
{
var wp = settings.Placement;
var wp = settings.Placement.ToWINDOWPLACEMENT();
WinApiHelper.SetWindowPlacement(window, wp);
}
catch (Exception ex)
Expand All @@ -165,29 +167,48 @@ private void SaveWindowState()
}

var windowHandle = new WindowInteropHelper(window).EnsureHandle();
var wp = NativeMethods.GetWindowPlacement(windowHandle);
var wp = new WINDOWPLACEMENT
{
length = (uint)Marshal.SizeOf<WINDOWPLACEMENT>()
};
unsafe
{
PInvoke.GetWindowPlacement((HWND)windowHandle, &wp);
}

// check for saveable values
if (wp.showCmd != SW.HIDE && wp.length > 0)
if (wp.showCmd != SHOW_WINDOW_CMD.SW_HIDE && wp.length > 0)
{
if (wp.showCmd == SW.NORMAL)
if (wp.showCmd == SHOW_WINDOW_CMD.SW_NORMAL)
{
if (UnsafeNativeMethods.GetWindowRect(windowHandle, out var rect))
unsafe
{
var monitor = NativeMethods.MonitorFromWindow(windowHandle, MonitorOptions.MONITOR_DEFAULTTONEAREST);
if (monitor != IntPtr.Zero)
var rect = new RECT();
PInvoke.GetWindowRect(new HWND(windowHandle), &rect);
if (rect.left != 0
|| rect.top != 0
|| rect.right != 0
|| rect.bottom != 0)
{
var monitorInfo = NativeMethods.GetMonitorInfo(monitor);
rect.Offset(monitorInfo.rcMonitor.Left - monitorInfo.rcWork.Left, monitorInfo.rcMonitor.Top - monitorInfo.rcWork.Top);
var monitor = PInvoke.MonitorFromWindow(new HWND(windowHandle), MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST);
if (monitor != IntPtr.Zero)
{
var monitorInfo = new MONITORINFO
{
cbSize = (uint)Marshal.SizeOf<MONITORINFO>()
};
PInvoke.GetMonitorInfo(monitor, &monitorInfo);
rect.Offset(monitorInfo.rcMonitor.left - monitorInfo.rcWork.left, monitorInfo.rcMonitor.top - monitorInfo.rcWork.top);
}

wp.rcNormalPosition = rect;
}

wp.normalPosition = rect;
}
}

if (!wp.normalPosition.IsEmpty)
if (!wp.rcNormalPosition.IsEmpty())
{
settings.Placement = wp;
settings.Placement = WindowPlacementSetting.FromWINDOWPLACEMENT(wp);
}
}

Expand All @@ -200,6 +221,5 @@ private void SaveWindowState()
Trace.TraceError($"{this}: The settings could not be saved! {e}");
}
}
#pragma warning restore 618
}
}
2 changes: 1 addition & 1 deletion src/MahApps.Metro/Controls/ContentControlEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using ControlzEx.Windows.Shell;
using ControlzEx;
using MahApps.Metro.ValueBoxes;

namespace MahApps.Metro.Controls
Expand Down
2 changes: 1 addition & 1 deletion src/MahApps.Metro/Controls/ContentPresenterEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using ControlzEx.Windows.Shell;
using ControlzEx;

namespace MahApps.Metro.Controls
{
Expand Down
Loading

0 comments on commit 8f28aba

Please sign in to comment.