diff --git a/WindowExample/App.xaml b/WindowExample/App.xaml new file mode 100644 index 00000000..cdd7d051 --- /dev/null +++ b/WindowExample/App.xaml @@ -0,0 +1,15 @@ + + + + + + + + + + diff --git a/WindowExample/App.xaml.cs b/WindowExample/App.xaml.cs new file mode 100644 index 00000000..565406a2 --- /dev/null +++ b/WindowExample/App.xaml.cs @@ -0,0 +1,14 @@ +using System.Configuration; +using System.Data; +using System.Windows; + +namespace WindowExample +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } + +} diff --git a/WindowExample/AssemblyInfo.cs b/WindowExample/AssemblyInfo.cs new file mode 100644 index 00000000..b0ec8275 --- /dev/null +++ b/WindowExample/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/WindowExample/MainWindow.xaml b/WindowExample/MainWindow.xaml new file mode 100644 index 00000000..fb1de52f --- /dev/null +++ b/WindowExample/MainWindow.xaml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WindowExample/MainWindow.xaml.cs b/WindowExample/MainWindow.xaml.cs new file mode 100644 index 00000000..e5cdc63a --- /dev/null +++ b/WindowExample/MainWindow.xaml.cs @@ -0,0 +1,127 @@ +using iNKORE.UI.WPF.Modern.Controls.Helpers; +using iNKORE.UI.WPF.Modern.Controls.Primitives; +using iNKORE.UI.WPF.Modern.Helpers.Styles; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace WindowExample +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + + private void RadioButton_WindowStyle_Click(object sender, RoutedEventArgs e) + { + if (sender is RadioButton btn && btn.Content is string val) + { + try + { + this.WindowStyle = (WindowStyle)Enum.Parse(typeof(WindowStyle), val); + } + catch + { + try + { + this.WindowStyle = (WindowStyle)Enum.Parse(typeof(WindowStyle), val + "Window"); + } + catch (Exception ex) + { + MessageBox.Show(ex.ToString()); + } + } + } + } + + private void RadioButton_ResizeMode_Click(object sender, RoutedEventArgs e) + { + if (sender is RadioButton btn && btn.Content is string val) + { + try + { + this.ResizeMode = (ResizeMode)Enum.Parse(typeof(ResizeMode), val); + } + catch (Exception ex) + { + MessageBox.Show(ex.ToString()); + } + } + } + + private void CheckBox_UseModernWindowStyle_Click(object sender, RoutedEventArgs e) + { + WindowHelper.SetUseModernWindowStyle(this, CheckBox_UseModernWindowStyle.IsChecked ?? false); + } + + private void RadioButton_SystemBackdropType_Click(object sender, RoutedEventArgs e) + { + if (sender is RadioButton btn && btn.Content is string val) + { + try + { + WindowHelper.SetSystemBackdropType(this, (BackdropType)Enum.Parse(typeof(BackdropType), val)); + } + catch (Exception ex) + { + MessageBox.Show(ex.ToString()); + } + } + + } + + private void CheckBox_ApplyBackground_Click(object sender, RoutedEventArgs e) + { + WindowHelper.SetApplyBackground(this, CheckBox_ApplyBackground.IsChecked ?? false); + } + + private void CheckBox_ApplyNoise_Click(object sender, RoutedEventArgs e) + { + WindowHelper.SetApplyNoise(this, CheckBox_ApplyBackground.IsChecked ?? false); + } + + private void TitleBarButtonAvailabilitySelector_Loaded(object sender, RoutedEventArgs e) + { + if(sender is ComboBox comboBox) + { + comboBox.ItemsSource = new string[] + { + "Auto", + "Collapsed", + "Disabled", + "Enabled" + }; + + comboBox.SelectedIndex = 0; + } + } + + private void TitleBarButtonAvailabilitySelector_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + if(sender is ComboBox box && box.Tag is DependencyProperty prop && box.SelectedItem is string val) + { + try + { + this.SetValue(prop, (TitleBarButtonAvailability)Enum.Parse(typeof(TitleBarButtonAvailability), val)); + } + catch (Exception ex) + { + MessageBox.Show(ex.ToString()); + } + } + } + } +} \ No newline at end of file diff --git a/WindowExample/WindowExample.csproj b/WindowExample/WindowExample.csproj new file mode 100644 index 00000000..a4e0201a --- /dev/null +++ b/WindowExample/WindowExample.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net6.0-windows + enable + enable + true + + + + + + + diff --git a/iNKORE.UI.WPF.Modern.sln b/iNKORE.UI.WPF.Modern.sln index 8f3dfcaf..f0b32a68 100644 --- a/iNKORE.UI.WPF.Modern.sln +++ b/iNKORE.UI.WPF.Modern.sln @@ -47,6 +47,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StarterKit", "source\sample EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SettingsPageExample", "source\samples\SettingsPageExample\SettingsPageExample.csproj", "{677DAAFA-C061-4C79-BAAE-5639BCD80448}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowExample", "WindowExample\WindowExample.csproj", "{936F7656-B5E8-44A8-8560-D954E1E68383}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -261,6 +263,26 @@ Global {677DAAFA-C061-4C79-BAAE-5639BCD80448}.Release|x64.Build.0 = Release|Any CPU {677DAAFA-C061-4C79-BAAE-5639BCD80448}.Release|x86.ActiveCfg = Release|Any CPU {677DAAFA-C061-4C79-BAAE-5639BCD80448}.Release|x86.Build.0 = Release|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|Any CPU.Build.0 = Debug|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|ARM.ActiveCfg = Debug|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|ARM.Build.0 = Debug|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|ARM64.Build.0 = Debug|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|x64.ActiveCfg = Debug|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|x64.Build.0 = Debug|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|x86.ActiveCfg = Debug|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|x86.Build.0 = Debug|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Release|Any CPU.ActiveCfg = Release|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Release|Any CPU.Build.0 = Release|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Release|ARM.ActiveCfg = Release|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Release|ARM.Build.0 = Release|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Release|ARM64.ActiveCfg = Release|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Release|ARM64.Build.0 = Release|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Release|x64.ActiveCfg = Release|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Release|x64.Build.0 = Release|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Release|x86.ActiveCfg = Release|Any CPU + {936F7656-B5E8-44A8-8560-D954E1E68383}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -275,6 +297,7 @@ Global {3614991C-ECC0-474A-BC8E-1D0A56FD0BDE} = {A96F98E9-18B5-4863-8F28-9B7BDF70A128} {B13E16CB-55E0-42CB-B761-216D82273473} = {A96F98E9-18B5-4863-8F28-9B7BDF70A128} {677DAAFA-C061-4C79-BAAE-5639BCD80448} = {A96F98E9-18B5-4863-8F28-9B7BDF70A128} + {936F7656-B5E8-44A8-8560-D954E1E68383} = {A96F98E9-18B5-4863-8F28-9B7BDF70A128} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {6251E140-0FAA-4DE9-B245-1C5BE188E578} diff --git a/source/iNKORE.UI.WPF.Modern/Controls/Primitives/TitleBarControl.cs b/source/iNKORE.UI.WPF.Modern/Controls/Primitives/TitleBarControl.cs index 03029cad..ee3c860e 100644 --- a/source/iNKORE.UI.WPF.Modern/Controls/Primitives/TitleBarControl.cs +++ b/source/iNKORE.UI.WPF.Modern/Controls/Primitives/TitleBarControl.cs @@ -615,7 +615,7 @@ public void RefreshButtonActualAvailabilities() } } - + InitializeSnapLayout(); } @@ -631,7 +631,7 @@ private void OnRightSystemOverlaySizeChanged(object sender, SizeChangedEventArgs private void OnMaximizeRestoreButtonLoaded(object sender, RoutedEventArgs e) { - InitializeSnapLayout(MaximizeRestoreButton); + InitializeSnapLayout(); } private void UpdateSystemOverlayLeftInset(double value) @@ -652,12 +652,31 @@ private void UpdateSystemOverlayRightInset(double value) } } + private void InitializeSnapLayout() + { + if(MaximizeRestoreButton != null) + { + InitializeSnapLayout(MaximizeRestoreButton); + } + } + private void InitializeSnapLayout(TitleBarButton maximizeButton) { if (!SnapLayout.IsSupported) return; - _snapLayout = new SnapLayout(); - _snapLayout.Register(maximizeButton); + if (maximizeButton.IsEnabled && maximizeButton.Visibility == Visibility.Visible) + { + _snapLayout = new SnapLayout(); + _snapLayout.Register(maximizeButton); + } + else + { + if(_snapLayout != null) + { + _snapLayout.Unregister(); + _snapLayout = null; + } + } } private void MinimizeWindow(object sender, ExecutedRoutedEventArgs e) diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/Styles/SnapLayout.cs b/source/iNKORE.UI.WPF.Modern/Helpers/Styles/SnapLayout.cs index a287f544..f88cc381 100644 --- a/source/iNKORE.UI.WPF.Modern/Helpers/Styles/SnapLayout.cs +++ b/source/iNKORE.UI.WPF.Modern/Helpers/Styles/SnapLayout.cs @@ -36,6 +36,8 @@ public class SnapLayout private SolidColorBrush _hoverColor; private SolidColorBrush _pressedColor; + public Button Target { get { return _button; } } + public void Register(Button button) { _isButtonFocused = false; @@ -57,6 +59,22 @@ public void Register(Button button) _button.IsHitTestVisible = false; } + public void Unregister() + { + if(_button != null) + { + _isButtonFocused = false; + + HwndSource hwnd = (HwndSource)PresentationSource.FromVisual(_button); + + if (hwnd != null) hwnd.RemoveHook(HwndSourceHook); + + _button.IsHitTestVisible = true; + _button = null; + } + + } + public static bool IsSupported => OSVersionHelper.IsWindows11OrGreater; /// @@ -161,6 +179,10 @@ private bool IsOverButton(IntPtr wParam, IntPtr lParam) { return true; // or not to true, that is the question } + catch + { + + } return false; } diff --git a/source/samples/StarterKit/MainWindow.xaml b/source/samples/StarterKit/MainWindow.xaml index 72eda33c..44884298 100644 --- a/source/samples/StarterKit/MainWindow.xaml +++ b/source/samples/StarterKit/MainWindow.xaml @@ -7,6 +7,7 @@ xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern" ui:WindowHelper.UseModernWindowStyle="True" ui:WindowHelper.SystemBackdropType="Mica" + ui:TitleBar.Height="36" mc:Ignorable="d" Title="Welcome!" Height="450" Width="800"> diff --git a/source/samples/StarterKit/StarterKit.csproj b/source/samples/StarterKit/StarterKit.csproj index 00c9d539..ae1ff04e 100644 --- a/source/samples/StarterKit/StarterKit.csproj +++ b/source/samples/StarterKit/StarterKit.csproj @@ -10,6 +10,7 @@ +