Skip to content

Commit

Permalink
(GH-3963) Bind the IsHitTestVisibleInChromeProperty to the content of…
Browse files Browse the repository at this point in the history
… the new ContentPresenterEx
  • Loading branch information
punker76 committed Nov 7, 2020
1 parent d6c8728 commit b59a503
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,14 @@ private MetroWindow GetTestWindow()
testWindow.Close();
}

testWindow = new MetroWindow() { Owner = this, WindowStartupLocation = WindowStartupLocation.CenterOwner, Title = "Another Test...", Width = 500, Height = 300 };
testWindow = new MetroWindow()
{
Owner = this,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Title = "Another Test...",
Width = 500,
Height = 300
};
testWindow.Closed += (o, args) => testWindow = null;
return testWindow;
}
Expand Down
32 changes: 32 additions & 0 deletions src/MahApps.Metro/Controls/ContentPresenterEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using ControlzEx.Windows.Shell;

namespace MahApps.Metro.Controls
{
public class ContentPresenterEx : ContentPresenter
{
static ContentPresenterEx()
{
ContentProperty.OverrideMetadata(typeof(ContentPresenterEx), new FrameworkPropertyMetadata(OnContentPropertyChanged));
}

private static void OnContentPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (e.OldValue is IInputElement && e.OldValue is DependencyObject oldInputElement)
{
BindingOperations.ClearBinding(oldInputElement, WindowChrome.IsHitTestVisibleInChromeProperty);
}

if (e.NewValue is IInputElement && e.NewValue is DependencyObject newInputElement)
{
BindingOperations.SetBinding(newInputElement, WindowChrome.IsHitTestVisibleInChromeProperty, new Binding { Path = new PropertyPath(WindowChrome.IsHitTestVisibleInChromeProperty), Source = d });
}
}
}
}
129 changes: 79 additions & 50 deletions src/MahApps.Metro/Themes/MetroWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:behaviors="clr-namespace:MahApps.Metro.Behaviors"
xmlns:controlzEx="urn:controlzex"
xmlns:converters="clr-namespace:MahApps.Metro.Converters"
xmlns:mah="clr-namespace:MahApps.Metro.Controls">
Expand Down Expand Up @@ -71,19 +72,21 @@
VerticalAlignment="Top"
Focusable="False">
<!-- the left window commands -->
<ContentPresenter x:Name="PART_LeftWindowCommands"
Height="{Binding TitleBarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
VerticalAlignment="Top"
Content="{Binding LeftWindowCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
DockPanel.Dock="Left"
Focusable="False" />
<mah:ContentPresenterEx x:Name="PART_LeftWindowCommands"
Height="{Binding TitleBarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
VerticalAlignment="Top"
controlzEx:WindowChrome.IsHitTestVisibleInChrome="True"
Content="{Binding LeftWindowCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
DockPanel.Dock="Left"
Focusable="False" />
<!-- the right window commands -->
<ContentPresenter x:Name="PART_RightWindowCommands"
Height="{Binding TitleBarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
VerticalAlignment="Top"
Content="{Binding RightWindowCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
DockPanel.Dock="Right"
Focusable="False" />
<mah:ContentPresenterEx x:Name="PART_RightWindowCommands"
Height="{Binding TitleBarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
VerticalAlignment="Top"
controlzEx:WindowChrome.IsHitTestVisibleInChrome="True"
Content="{Binding RightWindowCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
DockPanel.Dock="Right"
Focusable="False" />
<!-- the title bar -->
<mah:MetroThumbContentControl x:Name="PART_TitleBar"
Height="{Binding TitleBarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Expand All @@ -108,15 +111,16 @@
</DockPanel>

<!-- the window button commands -->
<ContentPresenter x:Name="PART_WindowButtonCommands"
Grid.Row="1"
Grid.RowSpan="2"
Grid.Column="3"
Height="{Binding TitleBarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
VerticalAlignment="Top"
Panel.ZIndex="1"
Content="{Binding WindowButtonCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Focusable="False" />
<mah:ContentPresenterEx x:Name="PART_WindowButtonCommands"
Grid.Row="1"
Grid.RowSpan="2"
Grid.Column="3"
Height="{Binding TitleBarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
VerticalAlignment="Top"
Panel.ZIndex="1"
controlzEx:WindowChrome.IsHitTestVisibleInChrome="True"
Content="{Binding WindowButtonCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Focusable="False" />

<!-- the main window content -->
<mah:MetroContentControl x:Name="PART_Content"
Expand All @@ -128,7 +132,10 @@
OnlyLoadTransition="True"
TransitionsEnabled="{TemplateBinding WindowTransitionsEnabled}"
UseLayoutRounding="True">
<ContentPresenter Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness, Converter={StaticResource ThicknessBindingConverter}, ConverterParameter={x:Static converters:ThicknessSideType.Top}}" UseLayoutRounding="False" />
<mah:ContentPresenterEx x:Name="PART_ContentPresenter"
Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness, Converter={StaticResource ThicknessBindingConverter}, ConverterParameter={x:Static converters:ThicknessSideType.Top}}"
controlzEx:WindowChrome.IsHitTestVisibleInChrome="True"
UseLayoutRounding="False" />
</mah:MetroContentControl>

<!-- disables the main content when a modal flyout is shown -->
Expand Down Expand Up @@ -244,11 +251,19 @@
</MultiTrigger>
<!-- HitTest visibility -->
<Trigger Property="GlowBrush" Value="{x:Null}">
<Setter TargetName="PART_Border" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="True" />
<Setter TargetName="PART_Border" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="False" />
<Setter TargetName="PART_ContentPresenter" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="False" />
<Setter TargetName="PART_LeftWindowCommands" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="False" />
<Setter TargetName="PART_RightWindowCommands" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="False" />
<Setter TargetName="PART_WindowButtonCommands" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="False" />
</Trigger>
<Trigger Property="ResizeMode" Value="NoResize">
<Setter Property="ResizeBorderThickness" Value="0" />
<Setter TargetName="PART_Border" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="False" />
<Setter TargetName="PART_Border" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="True" />
<Setter TargetName="PART_ContentPresenter" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="True" />
<Setter TargetName="PART_LeftWindowCommands" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="True" />
<Setter TargetName="PART_RightWindowCommands" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="True" />
<Setter TargetName="PART_TitleBar" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="True" />
<Setter TargetName="PART_WindowButtonCommands" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="True" />
</Trigger>
<!-- no icon and no icon content template -> collapse the icon content control -->
<MultiTrigger>
Expand Down Expand Up @@ -354,33 +369,36 @@
Panel.ZIndex="1"
Focusable="False">
<!-- the left window commands -->
<ContentPresenter x:Name="PART_LeftWindowCommands"
Height="{Binding TitleBarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
VerticalAlignment="Top"
Content="{Binding LeftWindowCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
DockPanel.Dock="Left"
Focusable="False" />
<mah:ContentPresenterEx x:Name="PART_LeftWindowCommands"
Height="{Binding TitleBarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
VerticalAlignment="Top"
controlzEx:WindowChrome.IsHitTestVisibleInChrome="True"
Content="{Binding LeftWindowCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
DockPanel.Dock="Left"
Focusable="False" />
<!-- the right window commands -->
<ContentPresenter x:Name="PART_RightWindowCommands"
Height="{Binding TitleBarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
VerticalAlignment="Top"
Content="{Binding RightWindowCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
DockPanel.Dock="Right"
Focusable="False" />
<mah:ContentPresenterEx x:Name="PART_RightWindowCommands"
Height="{Binding TitleBarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
VerticalAlignment="Top"
controlzEx:WindowChrome.IsHitTestVisibleInChrome="True"
Content="{Binding RightWindowCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
DockPanel.Dock="Right"
Focusable="False" />
<!-- the fake title bar -->
<Grid />
</DockPanel>

<!-- the window button commands -->
<ContentPresenter x:Name="PART_WindowButtonCommands"
Grid.Row="1"
Grid.RowSpan="2"
Grid.Column="3"
Height="{Binding TitleBarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
VerticalAlignment="Top"
Panel.ZIndex="1"
Content="{Binding WindowButtonCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Focusable="False" />
<mah:ContentPresenterEx x:Name="PART_WindowButtonCommands"
Grid.Row="1"
Grid.RowSpan="2"
Grid.Column="3"
Height="{Binding TitleBarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
VerticalAlignment="Top"
Panel.ZIndex="1"
controlzEx:WindowChrome.IsHitTestVisibleInChrome="True"
Content="{Binding WindowButtonCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Focusable="False" />

<!-- the main window content -->
<mah:MetroContentControl x:Name="PART_Content"
Expand All @@ -392,7 +410,10 @@
OnlyLoadTransition="True"
TransitionsEnabled="{TemplateBinding WindowTransitionsEnabled}"
UseLayoutRounding="True">
<ContentPresenter Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness, Converter={StaticResource ThicknessBindingConverter}, ConverterParameter={x:Static converters:ThicknessSideType.Top}}" UseLayoutRounding="False" />
<mah:ContentPresenterEx x:Name="PART_ContentPresenter"
Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness, Converter={StaticResource ThicknessBindingConverter}, ConverterParameter={x:Static converters:ThicknessSideType.Top}}"
controlzEx:WindowChrome.IsHitTestVisibleInChrome="True"
UseLayoutRounding="False" />
</mah:MetroContentControl>

<!-- disables the main content when a modal flyout is shown -->
Expand Down Expand Up @@ -525,11 +546,19 @@
</MultiTrigger>
<!-- HitTest visibility -->
<Trigger Property="GlowBrush" Value="{x:Null}">
<Setter TargetName="PART_Border" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="True" />
<Setter TargetName="PART_Border" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="False" />
<Setter TargetName="PART_ContentPresenter" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="False" />
<Setter TargetName="PART_LeftWindowCommands" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="False" />
<Setter TargetName="PART_RightWindowCommands" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="False" />
<Setter TargetName="PART_WindowButtonCommands" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="False" />
</Trigger>
<Trigger Property="ResizeMode" Value="NoResize">
<Setter Property="ResizeBorderThickness" Value="0" />
<Setter TargetName="PART_Border" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="False" />
<Setter TargetName="PART_Border" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="True" />
<Setter TargetName="PART_ContentPresenter" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="True" />
<Setter TargetName="PART_LeftWindowCommands" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="True" />
<Setter TargetName="PART_RightWindowCommands" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="True" />
<Setter TargetName="PART_TitleBar" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="True" />
<Setter TargetName="PART_WindowButtonCommands" Property="controlzEx:WindowChrome.IsHitTestVisibleInChrome" Value="True" />
</Trigger>
<!-- no icon and no icon content template -> collapse the icon content control -->
<MultiTrigger>
Expand Down

0 comments on commit b59a503

Please sign in to comment.