diff --git a/MahApps.Metro/Behaviours/BorderlessWindowBehavior.cs b/MahApps.Metro/Behaviours/BorderlessWindowBehavior.cs index 62810516e9..b7daec0679 100644 --- a/MahApps.Metro/Behaviours/BorderlessWindowBehavior.cs +++ b/MahApps.Metro/Behaviours/BorderlessWindowBehavior.cs @@ -7,6 +7,11 @@ using System.Windows.Media; using MahApps.Metro.Controls; using MahApps.Metro.Native; +#if NET_4 +using Microsoft.Windows.Shell; +#else +using System.Windows.Shell; +#endif namespace MahApps.Metro.Behaviours { @@ -14,15 +19,23 @@ public class BorderlessWindowBehavior : Behavior { public static readonly DependencyProperty ResizeWithGripProperty = DependencyProperty.Register("ResizeWithGrip", typeof(bool), typeof(BorderlessWindowBehavior), new PropertyMetadata(true)); public static readonly DependencyProperty AutoSizeToContentProperty = DependencyProperty.Register("AutoSizeToContent", typeof(bool), typeof(BorderlessWindowBehavior), new PropertyMetadata(false)); - public static readonly DependencyProperty EnableDWMDropShadowProperty = - DependencyProperty.Register("EnableDWMDropShadow", typeof(bool), typeof(BorderlessWindowBehavior), new PropertyMetadata(false, new PropertyChangedCallback((obj, args) => + public static readonly DependencyProperty EnableDWMDropShadowProperty = DependencyProperty.Register("EnableDWMDropShadow", typeof(bool), typeof(BorderlessWindowBehavior), new PropertyMetadata(false)); + + public static readonly DependencyProperty AllowsTransparencyProperty = + DependencyProperty.Register("AllowsTransparency", typeof(bool), typeof(BorderlessWindowBehavior), new PropertyMetadata(true, new PropertyChangedCallback((obj, args) => { var behaviorClass = ((BorderlessWindowBehavior)obj); if (behaviorClass.AssociatedObject != null) - behaviorClass.AssociatedObject.AllowsTransparency = !(bool)args.NewValue; + behaviorClass.AssociatedObject.AllowsTransparency = (bool)args.NewValue; }))); + public bool AllowsTransparency + { + get { return (bool)GetValue(AllowsTransparencyProperty); } + set { SetValue(AllowsTransparencyProperty, value); } + } + public bool EnableDWMDropShadow { get { return (bool)GetValue(EnableDWMDropShadowProperty); } @@ -84,8 +97,9 @@ protected override void OnAttached() AssociatedObject.SourceInitialized += AssociatedObject_SourceInitialized; AssociatedObject.WindowStyle = WindowStyle.None; - AssociatedObject.AllowsTransparency = !EnableDWMDropShadow; + AssociatedObject.AllowsTransparency = AllowsTransparency; AssociatedObject.StateChanged += AssociatedObjectStateChanged; + AssociatedObject.SetValue(WindowChrome.GlassFrameThicknessProperty, new Thickness(-1)); if (AssociatedObject is MetroWindow) { @@ -97,6 +111,10 @@ protected override void OnAttached() Border = ancestors; if (ShouldHaveBorder()) AddBorder(); + var titleBar = window.GetPart("PART_TitleBar"); + titleBar.SetValue(WindowChrome.IsHitTestVisibleInChromeProperty, true); + var windowCommands = window.GetPart("PART_WindowCommands"); + windowCommands.SetValue(WindowChrome.IsHitTestVisibleInChromeProperty, true); }; switch (AssociatedObject.ResizeMode) @@ -260,25 +278,22 @@ private IntPtr HwndHook(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam, break; case Constants.WM_NCPAINT: { - if (!ShouldHaveBorder()) + if (ShouldHaveBorder()) + { + this.AddBorder(); + } + else if (EnableDWMDropShadow) { - MetroWindow w = AssociatedObject as MetroWindow; - if (!(w != null && w.GlowBrush != null)) + var metroWindow = AssociatedObject as MetroWindow; + if (!(metroWindow != null && metroWindow.GlowBrush != null)) { var val = 2; UnsafeNativeMethods.DwmSetWindowAttribute(_mHWND, 2, ref val, 4); var m = new MARGINS { bottomHeight = 1, leftWidth = 1, rightWidth = 1, topHeight = 1 }; UnsafeNativeMethods.DwmExtendFrameIntoClientArea(_mHWND, ref m); } - - // i think we don't need this, cause after minimizing on taskbar, no border is shown - //if (Border != null) - //Border.BorderThickness = new Thickness(0); - } - else - { - AddBorder(); } + handled = true; } break; diff --git a/MahApps.Metro/MahApps.Metro.csproj b/MahApps.Metro/MahApps.Metro.csproj index 69490d4d55..c128f1062d 100644 --- a/MahApps.Metro/MahApps.Metro.csproj +++ b/MahApps.Metro/MahApps.Metro.csproj @@ -26,7 +26,7 @@ full false bin\Debug\ - DEBUG;TRACE + TRACE;DEBUG;NET_4 prompt 4 @@ -34,7 +34,7 @@ none true bin\Release\ - TRACE + TRACE;NET_4 prompt 4 @@ -43,6 +43,9 @@ mahapps.metro.pfx + + ..\packages\Microsoft.Windows.Shell.3.0.1.0\lib\net40\Microsoft.Windows.Shell.dll + False @@ -441,4 +444,4 @@ --> - + \ No newline at end of file diff --git a/MahApps.Metro/MahApps.Metro.nuspec b/MahApps.Metro/MahApps.Metro.nuspec index 6fd58ff6b3..f5b43ce443 100644 --- a/MahApps.Metro/MahApps.Metro.nuspec +++ b/MahApps.Metro/MahApps.Metro.nuspec @@ -22,4 +22,9 @@ + + + + + \ No newline at end of file diff --git a/MahApps.Metro/packages.config b/MahApps.Metro/packages.config index b2d602f9c2..b371b6adf9 100644 --- a/MahApps.Metro/packages.config +++ b/MahApps.Metro/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file diff --git a/packages/Microsoft.Windows.Shell.3.0.1.0/Microsoft.Windows.Shell.3.0.1.0.nupkg b/packages/Microsoft.Windows.Shell.3.0.1.0/Microsoft.Windows.Shell.3.0.1.0.nupkg new file mode 100644 index 0000000000..e346750799 Binary files /dev/null and b/packages/Microsoft.Windows.Shell.3.0.1.0/Microsoft.Windows.Shell.3.0.1.0.nupkg differ diff --git a/packages/Microsoft.Windows.Shell.3.0.1.0/Microsoft.Windows.Shell.3.0.1.0.nuspec b/packages/Microsoft.Windows.Shell.3.0.1.0/Microsoft.Windows.Shell.3.0.1.0.nuspec new file mode 100644 index 0000000000..b302ed8818 --- /dev/null +++ b/packages/Microsoft.Windows.Shell.3.0.1.0/Microsoft.Windows.Shell.3.0.1.0.nuspec @@ -0,0 +1,15 @@ + + + + Microsoft.Windows.Shell + 3.0.1.0 + Microsoft.Windows.Shell + Gareth Evans + Gareth Evans + false + Provides Windows Chrome and Taskbar integration facilities + + + + + \ No newline at end of file diff --git a/packages/Microsoft.Windows.Shell.3.0.1.0/lib/net40/Microsoft.Windows.Shell.dll b/packages/Microsoft.Windows.Shell.3.0.1.0/lib/net40/Microsoft.Windows.Shell.dll new file mode 100644 index 0000000000..d525604f43 Binary files /dev/null and b/packages/Microsoft.Windows.Shell.3.0.1.0/lib/net40/Microsoft.Windows.Shell.dll differ diff --git a/packages/Microsoft.Windows.Shell.3.0.1.0/lib/net40/Microsoft.Windows.Shell.pdb b/packages/Microsoft.Windows.Shell.3.0.1.0/lib/net40/Microsoft.Windows.Shell.pdb new file mode 100644 index 0000000000..9692faa5ff Binary files /dev/null and b/packages/Microsoft.Windows.Shell.3.0.1.0/lib/net40/Microsoft.Windows.Shell.pdb differ diff --git a/samples/MetroDemo/InteropDemo.xaml b/samples/MetroDemo/InteropDemo.xaml new file mode 100644 index 0000000000..7e57caf744 --- /dev/null +++ b/samples/MetroDemo/InteropDemo.xaml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/MetroDemo/InteropDemo.xaml.cs b/samples/MetroDemo/InteropDemo.xaml.cs new file mode 100644 index 0000000000..e127c56e4a --- /dev/null +++ b/samples/MetroDemo/InteropDemo.xaml.cs @@ -0,0 +1,10 @@ +namespace MetroDemo +{ + public partial class InteropDemo + { + public InteropDemo() + { + InitializeComponent(); + } + } +} diff --git a/samples/MetroDemo/MainWindow.xaml b/samples/MetroDemo/MainWindow.xaml index 3fdb53af24..b9ef11bd77 100644 --- a/samples/MetroDemo/MainWindow.xaml +++ b/samples/MetroDemo/MainWindow.xaml @@ -6,7 +6,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Title="MahApps.Metro.Demo" - Width="800" + Width="960" Height="600" Icon="mahapps.metro.logo2.ico" ShowIconOnTitleBar="true" @@ -44,6 +44,7 @@