Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/MahApps.Metro.Samples/MahApps.Metro.Demo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
Closing="MetroWindow_Closing"
GlowBrush="{DynamicResource AccentColorBrush}"
Icon="mahapps.metro.logo2.ico"
LeftWindowCommandsOverlayBehavior="Never"
NonActiveGlowBrush="#CDFF0000"
RightWindowCommandsOverlayBehavior="Never"
ShowIconOnTitleBar="True"
ShowTitleBar="{Binding ShowMyTitleBar, Mode=OneWay}"
ShowTitleBar="{Binding ShowMyTitleBar, Mode=TwoWay}"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">
<!--
Expand Down Expand Up @@ -188,7 +186,7 @@
<MenuItem Header="Window">
<MenuItem Header="ShowTitleBar"
IsCheckable="True"
IsChecked="{Binding Path=ShowMyTitleBar, UpdateSourceTrigger=PropertyChanged}" />
IsChecked="{Binding Path=ShowMyTitleBar, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<MenuItem Header="ShowInTaskbar"
IsCheckable="True"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}, Path=ShowInTaskbar}" />
Expand Down
49 changes: 15 additions & 34 deletions src/MahApps.Metro/Controls/MetroWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public class MetroWindow : Window
public static readonly DependencyProperty RightWindowCommandsProperty = DependencyProperty.Register("RightWindowCommands", typeof(WindowCommands), typeof(MetroWindow), new PropertyMetadata(null, UpdateLogicalChilds));
public static readonly DependencyProperty WindowButtonCommandsProperty = DependencyProperty.Register("WindowButtonCommands", typeof(WindowButtonCommands), typeof(MetroWindow), new PropertyMetadata(null, UpdateLogicalChilds));

public static readonly DependencyProperty LeftWindowCommandsOverlayBehaviorProperty = DependencyProperty.Register("LeftWindowCommandsOverlayBehavior", typeof(WindowCommandsOverlayBehavior), typeof(MetroWindow), new PropertyMetadata(WindowCommandsOverlayBehavior.Always));
public static readonly DependencyProperty RightWindowCommandsOverlayBehaviorProperty = DependencyProperty.Register("RightWindowCommandsOverlayBehavior", typeof(WindowCommandsOverlayBehavior), typeof(MetroWindow), new PropertyMetadata(WindowCommandsOverlayBehavior.Always));
public static readonly DependencyProperty LeftWindowCommandsOverlayBehaviorProperty = DependencyProperty.Register("LeftWindowCommandsOverlayBehavior", typeof(WindowCommandsOverlayBehavior), typeof(MetroWindow), new PropertyMetadata(WindowCommandsOverlayBehavior.Flyouts));
public static readonly DependencyProperty RightWindowCommandsOverlayBehaviorProperty = DependencyProperty.Register("RightWindowCommandsOverlayBehavior", typeof(WindowCommandsOverlayBehavior), typeof(MetroWindow), new PropertyMetadata(WindowCommandsOverlayBehavior.Flyouts));
public static readonly DependencyProperty WindowButtonCommandsOverlayBehaviorProperty = DependencyProperty.Register("WindowButtonCommandsOverlayBehavior", typeof(WindowCommandsOverlayBehavior), typeof(MetroWindow), new PropertyMetadata(WindowCommandsOverlayBehavior.Always));
public static readonly DependencyProperty IconOverlayBehaviorProperty = DependencyProperty.Register("IconOverlayBehavior", typeof(WindowCommandsOverlayBehavior), typeof(MetroWindow), new PropertyMetadata(WindowCommandsOverlayBehavior.Never));

Expand Down Expand Up @@ -474,7 +474,7 @@ private static void OnShowTitleBarPropertyChangedCallback(DependencyObject d, De
var window = (MetroWindow)d;
if (e.NewValue != e.OldValue)
{
window.SetVisibiltyForAllTitleElements((bool)e.NewValue);
window.SetVisibiltyForAllTitleElements();
}
}

Expand Down Expand Up @@ -503,29 +503,12 @@ private static void OnUseNoneWindowStylePropertyChangedCallback(DependencyObject
{
// if UseNoneWindowStyle = true no title bar should be shown
var useNoneWindowStyle = (bool)e.NewValue;
var window = (MetroWindow)d;
window.ToggleNoneWindowStyle(useNoneWindowStyle, window.ShowTitleBar);
}
}

private void ToggleNoneWindowStyle(bool useNoneWindowStyle, bool isTitleBarVisible)
{
// UseNoneWindowStyle means no title bar, window commands or min, max, close buttons
if (useNoneWindowStyle)
{
this.SetCurrentValue(ShowTitleBarProperty, false);
}
else
{
this.SetCurrentValue(ShowTitleBarProperty, isTitleBarVisible);
}
if (LeftWindowCommandsPresenter != null)
{
LeftWindowCommandsPresenter.Visibility = useNoneWindowStyle ? Visibility.Collapsed : Visibility.Visible;
}
if (RightWindowCommandsPresenter != null)
{
RightWindowCommandsPresenter.Visibility = useNoneWindowStyle ? Visibility.Collapsed : Visibility.Visible;
// UseNoneWindowStyle means no title bar, window commands or min, max, close buttons
if (useNoneWindowStyle)
{
((MetroWindow)d).SetCurrentValue(ShowTitleBarProperty, false);
}
}
}

Expand Down Expand Up @@ -615,7 +598,7 @@ private static void TitlebarHeightPropertyChangedCallback(DependencyObject depen
var window = (MetroWindow)dependencyObject;
if (e.NewValue != e.OldValue)
{
window.SetVisibiltyForAllTitleElements((int)e.NewValue > 0);
window.SetVisibiltyForAllTitleElements();
}
}

Expand All @@ -630,24 +613,24 @@ private void SetVisibiltyForIcon()
}
}

private void SetVisibiltyForAllTitleElements(bool visible)
private void SetVisibiltyForAllTitleElements()
{
this.SetVisibiltyForIcon();
var newVisibility = visible && this.ShowTitleBar ? Visibility.Visible : Visibility.Collapsed;
var newVisibility = this.TitlebarHeight > 0 && this.ShowTitleBar && !this.UseNoneWindowStyle ? Visibility.Visible : Visibility.Collapsed;

this.titleBar?.SetCurrentValue(VisibilityProperty, newVisibility);
this.titleBarBackground?.SetCurrentValue(VisibilityProperty, newVisibility);

newVisibility = this.LeftWindowCommandsOverlayBehavior.HasFlag(WindowCommandsOverlayBehavior.HiddenTitleBar) ? Visibility.Visible : newVisibility;
newVisibility = this.LeftWindowCommandsOverlayBehavior.HasFlag(WindowCommandsOverlayBehavior.HiddenTitleBar) && !this.UseNoneWindowStyle ? Visibility.Visible : newVisibility;
this.LeftWindowCommandsPresenter?.SetCurrentValue(VisibilityProperty, newVisibility);

newVisibility = this.RightWindowCommandsOverlayBehavior.HasFlag(WindowCommandsOverlayBehavior.HiddenTitleBar) ? Visibility.Visible : newVisibility;
newVisibility = this.RightWindowCommandsOverlayBehavior.HasFlag(WindowCommandsOverlayBehavior.HiddenTitleBar) && !this.UseNoneWindowStyle ? Visibility.Visible : newVisibility;
this.RightWindowCommandsPresenter?.SetCurrentValue(VisibilityProperty, newVisibility);

newVisibility = this.WindowButtonCommandsOverlayBehavior.HasFlag(WindowCommandsOverlayBehavior.HiddenTitleBar) ? Visibility.Visible : newVisibility;
this.WindowButtonCommandsPresenter?.SetCurrentValue(VisibilityProperty, newVisibility);

SetWindowEvents();
this.SetWindowEvents();
}

/// <summary>
Expand Down Expand Up @@ -1044,8 +1027,6 @@ private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
VisualStateManager.GoToState(this, "AfterLoaded", true);
}

this.ToggleNoneWindowStyle(this.UseNoneWindowStyle, this.ShowTitleBar);

if (this.Flyouts == null)
{
this.Flyouts = new FlyoutsControl();
Expand Down Expand Up @@ -1243,7 +1224,7 @@ public override void OnApplyTemplate()
this.windowTitleThumb = GetTemplateChild(PART_WindowTitleThumb) as Thumb;
this.flyoutModalDragMoveThumb = GetTemplateChild(PART_FlyoutModalDragMoveThumb) as Thumb;

this.SetVisibiltyForAllTitleElements(this.TitlebarHeight > 0);
this.SetVisibiltyForAllTitleElements();

var metroContentControl = GetTemplateChild(PART_Content) as MetroContentControl;
if (metroContentControl != null)
Expand Down
24 changes: 8 additions & 16 deletions src/MahApps.Metro/Themes/MetroWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
Grid.ColumnSpan="5"
Fill="{TemplateBinding WindowTitleBrush}"
Focusable="False"
StrokeThickness="0"
Visibility="{TemplateBinding ShowTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />
StrokeThickness="0" />

<!-- icon -->
<ContentControl x:Name="PART_Icon"
Expand All @@ -71,8 +70,7 @@
VerticalAlignment="Top"
Panel.ZIndex="1"
Content="{Binding LeftWindowCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Focusable="False"
Visibility="{TemplateBinding ShowTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />
Focusable="False" />

<Controls:MetroThumb x:Name="PART_WindowTitleThumb"
Grid.Row="1"
Expand All @@ -91,8 +89,7 @@
Content="{TemplateBinding Title}"
ContentCharacterCasing="{TemplateBinding TitleCharacterCasing}"
ContentTemplate="{TemplateBinding TitleTemplate}"
Focusable="False"
Visibility="{TemplateBinding ShowTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}">
Focusable="False">
<ContentControl.Foreground>
<MultiBinding Converter="{x:Static Converters:BackgroundToForegroundConverter.Instance}">
<Binding ElementName="PART_WindowTitleBackground"
Expand All @@ -113,8 +110,7 @@
VerticalAlignment="Top"
Panel.ZIndex="1"
Content="{Binding RightWindowCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Focusable="False"
Visibility="{TemplateBinding ShowTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />
Focusable="False" />

<!-- the window button commands -->
<ContentPresenter x:Name="PART_WindowButtonCommands"
Expand Down Expand Up @@ -306,8 +302,7 @@
Grid.ColumnSpan="5"
Fill="{TemplateBinding WindowTitleBrush}"
Focusable="False"
StrokeThickness="0"
Visibility="{TemplateBinding ShowTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />
StrokeThickness="0" />

<!-- icon -->
<ContentControl x:Name="PART_Icon"
Expand All @@ -331,8 +326,7 @@
VerticalAlignment="Top"
Panel.ZIndex="1"
Content="{Binding LeftWindowCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Focusable="False"
Visibility="{TemplateBinding ShowTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />
Focusable="False" />

<Controls:MetroThumb x:Name="PART_WindowTitleThumb"
Grid.Row="1"
Expand All @@ -352,8 +346,7 @@
Content="{TemplateBinding Title}"
ContentCharacterCasing="{TemplateBinding TitleCharacterCasing}"
ContentTemplate="{TemplateBinding TitleTemplate}"
Focusable="False"
Visibility="{TemplateBinding ShowTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}">
Focusable="False">
<ContentControl.Foreground>
<MultiBinding Converter="{x:Static Converters:BackgroundToForegroundConverter.Instance}">
<Binding ElementName="PART_WindowTitleBackground"
Expand All @@ -374,8 +367,7 @@
VerticalAlignment="Top"
Panel.ZIndex="1"
Content="{Binding RightWindowCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Focusable="False"
Visibility="{TemplateBinding ShowTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />
Focusable="False" />

<!-- the window button commands -->
<ContentPresenter x:Name="PART_WindowButtonCommands"
Expand Down
7 changes: 5 additions & 2 deletions src/Mahapps.Metro.Tests/Tests/MetroWindowTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@ public async Task WindowCommandsShouldHaveTheParentWindow()

[Fact]
[DisplayTestMethodName]
public async Task ShowsRightWindowCommandsOnTopByDefault()
public async Task CheckDefaultOverlayBehaviors()
{
await TestHost.SwitchToAppThread();

var window = await WindowHelpers.CreateInvisibleWindowAsync<MetroWindow>();

Assert.Equal(WindowCommandsOverlayBehavior.Always, window.RightWindowCommandsOverlayBehavior);
Assert.Equal(WindowCommandsOverlayBehavior.Never, window.IconOverlayBehavior);
Assert.Equal(WindowCommandsOverlayBehavior.Flyouts, window.LeftWindowCommandsOverlayBehavior);
Assert.Equal(WindowCommandsOverlayBehavior.Flyouts, window.RightWindowCommandsOverlayBehavior);
Assert.Equal(WindowCommandsOverlayBehavior.Always, window.WindowButtonCommandsOverlayBehavior);
}

[Fact]
Expand Down