Skip to content

Commit

Permalink
Fixes #18 by making the ContentPresenter of RibbonWindow hittest visi…
Browse files Browse the repository at this point in the history
…ble in the window chrome
  • Loading branch information
batzen committed Nov 16, 2014
1 parent d4ead88 commit 2bc7aa6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
24 changes: 17 additions & 7 deletions Fluent/Controls/RibbonWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Fluent
using System;
using System.Diagnostics.CodeAnalysis;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
Expand All @@ -28,10 +29,12 @@ namespace Fluent
/// </summary>
[SuppressMessage("Microsoft.Design", "CA1049")]
[TemplatePart(Name = PART_Icon, Type = typeof(UIElement))]
[TemplatePart(Name = PART_ContentPresenter, Type = typeof(UIElement))]
[TemplatePart(Name = PART_WindowCommands, Type = typeof(WindowCommands))]
public class RibbonWindow : Window
{
private const string PART_Icon = "PART_Icon";
private const string PART_ContentPresenter = "PART_ContentPresenter";
private const string PART_WindowCommands = "PART_WindowCommands";

private FrameworkElement iconImage;
Expand Down Expand Up @@ -380,13 +383,6 @@ public override void OnApplyTemplate()
this.WindowCommands = new WindowCommands();
}

var partWindowCommands = this.GetTemplateChild(PART_WindowCommands) as UIElement;

if (partWindowCommands != null)
{
WindowChrome.SetIsHitTestVisibleInChrome(partWindowCommands, true);
}

this.iconImage = this.GetTemplateChild(PART_Icon) as FrameworkElement;

if (this.iconImage != null)
Expand All @@ -396,6 +392,20 @@ public override void OnApplyTemplate()
this.iconImage.MouseUp += this.HandleIconMouseUp;
}

var partContentPresenter = this.GetTemplateChild(PART_ContentPresenter) as UIElement;

if (partContentPresenter != null)
{
WindowChrome.SetIsHitTestVisibleInChrome(partContentPresenter, true);
}

var partWindowCommands = this.GetTemplateChild(PART_WindowCommands) as UIElement;

if (partWindowCommands != null)
{
WindowChrome.SetIsHitTestVisibleInChrome(partWindowCommands, true);
}

// This has to be done when the theme is changed. Otherwise maximized windows have the wrong size.
if (this.WindowState == WindowState.Maximized)
{
Expand Down
8 changes: 4 additions & 4 deletions Fluent/Themes/Office2010/RibbonWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<Image x:Name="PART_Icon" Height="16" HorizontalAlignment="Left" VerticalAlignment="Top" Source="{Binding Icon, Converter={StaticResource IconConvert}, RelativeSource={RelativeSource TemplatedParent}}" Width="16" SnapsToDevicePixels="True"
Visibility="{TemplateBinding IsIconVisible, Converter={StaticResource BooleanToVisibilityConverter}}" />
</StackPanel>
<ContentPresenter Margin="8,1,8,8" x:Name="contentPresenter"/>
<ContentPresenter Margin="8,1,8,8" x:Name="PART_ContentPresenter"/>
<ResizeGrip x:Name="PART_ResizeGrip" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right"
VerticalAlignment="Bottom" Focusable="False" Margin="0,0,5.5,5.5" Background="Transparent"
Visibility="Collapsed"/>
Expand All @@ -79,7 +79,7 @@
<Trigger Property="WindowState" Value="Maximized">
<Setter Property="Margin" TargetName="PART_IconImage" Value="0,4,0,0"/>
<Setter Property="Margin" TargetName="adornerDecorator" Value="0"/>
<Setter Property="Margin" TargetName="contentPresenter" Value="0,0,0,0"/>
<Setter Property="Margin" TargetName="PART_ContentPresenter" Value="0,0,0,0"/>
<Setter Property="Margin" TargetName="rectangle" Value="15,4,0,1"/>
<Setter Property="Margin" TargetName="rectangle1" Value="0,4,15.1,1"/>
<Setter Property="Margin" TargetName="rectangle2" Value="50,4,50,1"/>
Expand Down Expand Up @@ -115,7 +115,7 @@
<Grid x:Name="grid" Background="{TemplateBinding Background}"/>
</Border>
</Border>
<ContentPresenter Margin="8,1,8,8" x:Name="contentPresenter"/>
<ContentPresenter Margin="8,1,8,8" x:Name="PART_ContentPresenter"/>
<ResizeGrip x:Name="PART_ResizeGrip" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right"
VerticalAlignment="Bottom" Focusable="False" Margin="0,0,5.5,5.5"
Cursor="SizeNWSE" Visibility="Collapsed"/>
Expand Down Expand Up @@ -143,7 +143,7 @@
<Setter Property="BorderThickness" TargetName="border2" Value="0,0,0,0"/>
<Setter Property="CornerRadius" TargetName="border2" Value="0,0,0,0"/>
<Setter Property="Margin" TargetName="PART_WindowCommands" Value="0,0,0,0"/>
<Setter Property="Margin" TargetName="contentPresenter" Value="0,0,0,0"/>
<Setter Property="Margin" TargetName="PART_ContentPresenter" Value="0,0,0,0"/>
<Setter Property="Height" TargetName="border2" Value="54"/>
<Setter Property="Margin"
TargetName="border4"
Expand Down
2 changes: 1 addition & 1 deletion Fluent/Themes/Office2013/RibbonWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
VerticalAlignment="Top"
HorizontalAlignment="Right"
Height="{Binding Path=(Fluent:RibbonProperties.TitleBarHeight), RelativeSource={RelativeSource Self}}" />
<ContentPresenter />
<ContentPresenter x:Name="PART_ContentPresenter" />
</Grid>
</AdornerDecorator>
<ResizeGrip x:Name="WindowResizeGrip"
Expand Down

0 comments on commit 2bc7aa6

Please sign in to comment.