Skip to content

Commit

Permalink
Fixes #29 and #112 by changing the way titlebar height and backstage …
Browse files Browse the repository at this point in the history
…height are used as offsets
  • Loading branch information
batzen committed Nov 19, 2015
1 parent 59fbee7 commit 909cf12
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 76 deletions.
24 changes: 2 additions & 22 deletions Fluent/Controls/BackstageAdorner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ namespace Fluent
/// </summary>
internal class BackstageAdorner : Adorner
{
#region Fields

// Backstage
private readonly Backstage backstage;

Expand All @@ -31,10 +29,6 @@ internal class BackstageAdorner : Adorner
// Collection of visual children
private readonly VisualCollection visualChildren;

#endregion

#region Constructors

/// <summary>
/// Constructor
/// </summary>
Expand Down Expand Up @@ -82,16 +76,6 @@ public void Clear()
this.visualChildren.Clear();
}

#endregion

// Adorner offset from top of window
private double GetTopOffset()
{
var topOffset = this.backstage.TranslatePoint(new Point(0, this.backstage.ActualHeight), this.AdornedElement).Y;

return topOffset;
}

#region Layout & Visual Children

/// <summary>
Expand All @@ -104,9 +88,7 @@ private double GetTopOffset()
/// <returns>The actual size used</returns>
protected override Size ArrangeOverride(Size finalSize)
{
var topOffset = this.GetTopOffset();

this.backstageContent.Arrange(new Rect(0, topOffset, finalSize.Width, Math.Max(0, finalSize.Height - topOffset)));
this.backstageContent.Arrange(new Rect(0, 0, finalSize.Width, Math.Max(0, finalSize.Height)));
return finalSize;
}

Expand All @@ -119,10 +101,8 @@ protected override Size ArrangeOverride(Size finalSize)
/// </returns>
protected override Size MeasureOverride(Size constraint)
{
var topOffset = this.GetTopOffset();

// TODO: fix it! (below ugly workaround) in measureoverride we cannot get RenderSize, we must use DesiredSize
this.backstageContent.Measure(new Size(this.AdornedElement.RenderSize.Width, Math.Max(0, this.AdornedElement.RenderSize.Height - topOffset)));
this.backstageContent.Measure(new Size(this.AdornedElement.RenderSize.Width, Math.Max(0, this.AdornedElement.RenderSize.Height)));
return this.AdornedElement.RenderSize;
}

Expand Down
37 changes: 29 additions & 8 deletions Fluent/Themes/Office2010/Controls/BackstageTabControl.xaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Fluent="clr-namespace:Fluent">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Fluent;component\Themes\Office2010\Controls\ScrollBarWhite.xaml" />
<ResourceDictionary Source="pack://application:,,,/Fluent;component\Themes\Office2010\Controls\BackstageControls.xaml" />
</ResourceDictionary.MergedDictionaries>

xmlns:Fluent="clr-namespace:Fluent"
xmlns:Converters="clr-namespace:Fluent.Converters">
<ControlTemplate x:Key="BackstageButtonControlTemplate"
TargetType="{x:Type Fluent:Button}">
<Grid Background="#00000000">
Expand Down Expand Up @@ -75,6 +71,7 @@
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>

<Style x:Key="BackstageButtonStyle"
TargetType="{x:Type Fluent:Button}">
<Setter Property="FocusVisualStyle"
Expand All @@ -90,6 +87,7 @@
<Setter Property="Foreground"
Value="{DynamicResource BackstageFontBrush}" />
</Style>

<Style TargetType="{x:Type Fluent:SeparatorTabItem}"
x:Key="BackstageSeparatorTabItemStyle">
<Setter Property="Template">
Expand Down Expand Up @@ -155,8 +153,16 @@
BasedOn="{StaticResource BackstageSeparatorTabItemStyle}" />
</ResourceDictionary>
</ControlTemplate.Resources>
<Grid Margin="0"
Background="{DynamicResource BackstageBackgroundBrush}">
<Grid Background="{DynamicResource BackstageBackgroundBrush}">
<Grid.Margin>
<MultiBinding Converter="{x:Static Converters:StaticConverters.ThicknessConverter}">
<Binding Source="0" />
<Binding RelativeSource="{RelativeSource Self}"
Path="(Fluent:RibbonProperties.TitleBarHeight)" />
<Binding Source="0" />
<Binding Source="0" />
</MultiBinding>
</Grid.Margin>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="107"
Width="Auto" />
Expand Down Expand Up @@ -247,8 +253,11 @@
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>

<Style x:Key="BackstageStyle"
TargetType="{x:Type Fluent:BackstageTabControl}">
<Setter Property="OverridesDefaultStyle"
Value="True" />
<Setter Property="Foreground"
Value="{DynamicResource DefaultFontBrush}" />
<Setter Property="Template"
Expand All @@ -259,5 +268,17 @@
Value="{Binding Background, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:Backstage}}, FallbackValue=Red}" />
<Setter Property="ItemsPanelBackground"
Value="{DynamicResource BackstagePanelBackgroundBrush}" />
<Setter Property="Margin">
<Setter.Value>
<MultiBinding Converter="{x:Static Converters:StaticConverters.ThicknessConverter}"
ConverterParameter="0 0 0 0">
<Binding Source="0" />
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Fluent:Backstage}}"
Path="ActualHeight" />
<Binding Source="0" />
<Binding Source="0" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
64 changes: 30 additions & 34 deletions Fluent/Themes/Office2013/Controls/BackstageTabControl.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Fluent="clr-namespace:Fluent"
xmlns:Internal="clr-namespace:Fluent.Internal"
xmlns:Converters="clr-namespace:Fluent.Converters">
<ControlTemplate x:Key="BackstageButtonControlTemplate"
TargetType="{x:Type Fluent:Button}">
Expand Down Expand Up @@ -112,11 +111,10 @@
Value="{DynamicResource BackstageBackButtonTemplate}" />
</Style>


<Style TargetType="{x:Type Fluent:SeparatorTabItem}"
x:Key="BackstageSeparatorTabItemStyle">
<Setter Property="Margin"
Value="25,10,20,10"></Setter>
Value="25,10,20,10" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Fluent:SeparatorTabItem}">
Expand Down Expand Up @@ -198,42 +196,14 @@
</Storyboard>
</ResourceDictionary>
</ControlTemplate.Resources>
<Grid x:Name="grid"
Margin="0"
Background="{DynamicResource BackstageBackgroundBrush}">
<Grid x:Name="grid">
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="115"
Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid Height="Auto"
Grid.Column="1">
<Grid.Resources>
<ResourceDictionary>
<Style x:Key="{x:Type Fluent:Button}"
TargetType="{x:Type Fluent:Button}"
BasedOn="{StaticResource BackstageButtonStyle}" />
</ResourceDictionary>
</Grid.Resources>
<ContentPresenter x:Name="PART_SelectedContentHost"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Height="Auto"
Grid.Column="1"
ContentSource="SelectedContent" />
</Grid>
<Grid VerticalAlignment="Stretch"
Background="{DynamicResource RibbonThemeColorBrush}">
<Grid.Margin>
<MultiBinding Converter="{x:Static Converters:StaticConverters.ThicknessConverter}">
<Binding Source="{x:Static Internal:DoubleUtil.Zero}" />
<Binding RelativeSource="{RelativeSource Self}"
Path="(Fluent:RibbonProperties.TitleBarHeight)"
Converter="{x:Static Converters:StaticConverters.InvertNumericConverter}" />
<Binding Source="{x:Static Internal:DoubleUtil.Zero}" />
<Binding Source="{x:Static Internal:DoubleUtil.Zero}" />
</MultiBinding>
</Grid.Margin>
<Button x:Name="backbutton"
Style="{DynamicResource BackstageBackButtonStyle}"
Command="{x:Static Fluent:RibbonCommands.OpenBackstage}"
Expand All @@ -247,6 +217,32 @@
<ItemsPresenter Margin="0,69,0,0"
Height="Auto" />
</Grid>
<Grid Height="Auto"
Grid.Column="1"
Background="{DynamicResource BackstageBackgroundBrush}">
<Grid.Margin>
<MultiBinding Converter="{x:Static Converters:StaticConverters.ThicknessConverter}">
<Binding Source="0" />
<Binding RelativeSource="{RelativeSource Self}"
Path="(Fluent:RibbonProperties.TitleBarHeight)" />
<Binding Source="0" />
<Binding Source="0" />
</MultiBinding>
</Grid.Margin>
<Grid.Resources>
<ResourceDictionary>
<Style x:Key="{x:Type Fluent:Button}"
TargetType="{x:Type Fluent:Button}"
BasedOn="{StaticResource BackstageButtonStyle}" />
</ResourceDictionary>
</Grid.Resources>
<ContentPresenter x:Name="PART_SelectedContentHost"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Height="Auto"
Grid.Column="1"
ContentSource="SelectedContent" />
</Grid>
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding IsOpen, RelativeSource={RelativeSource AncestorType={x:Type Fluent:Backstage}}}"
Expand Down Expand Up @@ -274,14 +270,14 @@

<Style x:Key="BackstageStyle"
TargetType="{x:Type Fluent:BackstageTabControl}">
<Setter Property="OverridesDefaultStyle"
Value="True" />
<Setter Property="Foreground"
Value="{DynamicResource DefaultFontBrush}" />
<Setter Property="Template"
Value="{DynamicResource BackstageControlTemplate}" />
<Setter Property="FocusVisualStyle"
Value="{DynamicResource ControlStyleEmptyFocus}" />
<Setter Property="Margin"
Value="0,-24,0,1" />
<Setter Property="Background"
Value="{Binding Background, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:Backstage}}, FallbackValue=Red}" />
<Setter Property="ItemsPanelBackground"
Expand Down
43 changes: 31 additions & 12 deletions Fluent/Themes/Windows8/Controls/BackstageTabControl.xaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Fluent="clr-namespace:Fluent">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Fluent;component\Themes\Windows8\Controls\ScrollBarWhite.xaml" />
<ResourceDictionary Source="pack://application:,,,/Fluent;component\Themes\Windows8\Controls\BackstageControls.xaml" />
</ResourceDictionary.MergedDictionaries>

xmlns:Fluent="clr-namespace:Fluent"
xmlns:Converters="clr-namespace:Fluent.Converters">
<ControlTemplate x:Key="BackstageButtonControlTemplate"
TargetType="{x:Type Fluent:Button}">
<Grid Background="#00000000">
Expand Down Expand Up @@ -75,6 +71,7 @@
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>

<Style x:Key="BackstageButtonStyle"
TargetType="{x:Type Fluent:Button}">
<Setter Property="FocusVisualStyle"
Expand All @@ -90,6 +87,7 @@
<Setter Property="Foreground"
Value="{DynamicResource BackstageFontBrush}" />
</Style>

<Style TargetType="{x:Type Fluent:SeparatorTabItem}"
x:Key="BackstageSeparatorTabItemStyle">
<Setter Property="Template">
Expand Down Expand Up @@ -155,8 +153,16 @@
BasedOn="{StaticResource BackstageSeparatorTabItemStyle}" />
</ResourceDictionary>
</ControlTemplate.Resources>
<Grid Margin="0"
Background="{DynamicResource BackstageBackgroundBrush}">
<Grid Background="{DynamicResource BackstageBackgroundBrush}">
<Grid.Margin>
<MultiBinding Converter="{x:Static Converters:StaticConverters.ThicknessConverter}">
<Binding Source="0" />
<Binding RelativeSource="{RelativeSource Self}"
Path="(Fluent:RibbonProperties.TitleBarHeight)" />
<Binding Source="0" />
<Binding Source="0" />
</MultiBinding>
</Grid.Margin>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="107"
Width="Auto" />
Expand Down Expand Up @@ -213,8 +219,7 @@
Width="6"
Height="Auto"
BorderBrush="{DynamicResource RibbonTopBorderBrush}"
BorderThickness="0,0,1,0"
/>
BorderThickness="0,0,1,0" />
<ItemsPresenter Margin="0,5,0,0"
Height="Auto">
</ItemsPresenter>
Expand All @@ -223,8 +228,7 @@
VerticalAlignment="Top"
Height="1"
Grid.ColumnSpan="2"
Background="{TemplateBinding Background}"
>
Background="{TemplateBinding Background}">
<Rectangle Stroke="{x:Null}"
StrokeThickness="0"
Fill="{DynamicResource BackstageTopBackgroundBrush}" />
Expand All @@ -247,8 +251,11 @@
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>

<Style x:Key="BackstageStyle"
TargetType="{x:Type Fluent:BackstageTabControl}">
<Setter Property="OverridesDefaultStyle"
Value="True" />
<Setter Property="Foreground"
Value="{DynamicResource DefaultFontBrush}" />
<Setter Property="Template"
Expand All @@ -259,5 +266,17 @@
Value="{Binding Background, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:Backstage}}, FallbackValue=Red}" />
<Setter Property="ItemsPanelBackground"
Value="{DynamicResource BackstagePanelBackgroundBrush}" />
<Setter Property="Margin">
<Setter.Value>
<MultiBinding Converter="{x:Static Converters:StaticConverters.ThicknessConverter}"
ConverterParameter="0 0 0 0">
<Binding Source="0" />
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Fluent:Backstage}}"
Path="ActualHeight" />
<Binding Source="0" />
<Binding Source="0" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

0 comments on commit 909cf12

Please sign in to comment.