Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow showing title bar while showing dialog (Fixes #2109) #2534

Merged
merged 1 commit into from
Jun 4, 2016
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
30 changes: 30 additions & 0 deletions MahApps.Metro/Controls/MetroWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class MetroWindow : Window
public static readonly DependencyProperty IconBitmapScalingModeProperty = DependencyProperty.Register("IconBitmapScalingMode", typeof(BitmapScalingMode), typeof(MetroWindow), new PropertyMetadata(BitmapScalingMode.HighQuality));
public static readonly DependencyProperty ShowTitleBarProperty = DependencyProperty.Register("ShowTitleBar", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true, OnShowTitleBarPropertyChangedCallback, OnShowTitleBarCoerceValueCallback));

public static readonly DependencyProperty ShowDialogsOverTitleBarProperty = DependencyProperty.Register("ShowDialogsOverTitleBar", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true, OnShowDialogsOverTitleBarPropertyChangedCallback));

public static readonly DependencyProperty ShowMinButtonProperty = DependencyProperty.Register("ShowMinButton", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true));
public static readonly DependencyProperty ShowMaxRestoreButtonProperty = DependencyProperty.Register("ShowMaxRestoreButton", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true));
public static readonly DependencyProperty ShowCloseButtonProperty = DependencyProperty.Register("ShowCloseButton", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true));
Expand Down Expand Up @@ -358,6 +360,33 @@ private static void OnShowIconOnTitleBarPropertyChangedCallback(DependencyObject
}
}

/// <summary>
/// Get/sets whether dialogs show over the title bar.
/// </summary>
public bool ShowDialogsOverTitleBar
{
get { return (bool)GetValue(ShowDialogsOverTitleBarProperty); }
set { SetValue(ShowDialogsOverTitleBarProperty, value); }
}

private static void OnShowDialogsOverTitleBarPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var window = (MetroWindow)d;
if (e.NewValue != e.OldValue)
{
window.UpdateDialogPlacement((bool)e.NewValue);
}
}

private void UpdateDialogPlacement(bool shouldShowOverTitleBar)
{
if (overlayBox != null)
{
int row = shouldShowOverTitleBar == true ? 0 : 1;
Grid.SetRow(overlayBox, row);
}
}

/// <summary>
/// Gets/sets edge mode of the titlebar icon.
/// </summary>
Expand Down Expand Up @@ -966,6 +995,7 @@ public override void OnApplyTemplate()
this.flyoutModalDragMoveThumb = GetTemplateChild(PART_FlyoutModalDragMoveThumb) as Thumb;

this.SetVisibiltyForAllTitleElements(this.TitlebarHeight > 0);
this.UpdateDialogPlacement(ShowDialogsOverTitleBar);
}

protected IntPtr CriticalHandle
Expand Down
7 changes: 6 additions & 1 deletion samples/MetroDemo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
mc:Ignorable="d"
d:DesignHeight="600"
d:DesignWidth="800"
d:DataContext="{d:DesignInstance MetroDemo:MainWindowViewModel}">
d:DataContext="{d:DesignInstance MetroDemo:MainWindowViewModel}"
ShowDialogsOverTitleBar="True">
<!--
if using DialogParticipation on Windows which open/close frequently you will get a
memory leak unless you unregister. The easiest way to do this is in your Closing/Unloaded
Expand Down Expand Up @@ -164,6 +165,10 @@
Header="Use Accent?"
IsCheckable="True"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}, Path=UseAccentForDialogs}" />
<MenuItem x:Name="HideTitleBarForDialogsMenuItem"
Header="Hide Title Bar When Displaying Dialog?"
IsCheckable="True"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}, Path=HideTitleBarForDialogs}" />
<Separator />
<MenuItem Click="ShowInputDialog" Header="Show InputDialog" />
<MenuItem Click="ShowLoginDialog" Header="Show LoginDialog" />
Expand Down
22 changes: 22 additions & 0 deletions samples/MetroDemo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,28 @@ private static void ToggleUseAccentForDialogsPropertyChangedCallback(DependencyO
}
}

public bool HideTitleBarForDialogs
{
get { return (bool)GetValue(HideTitleBarForDialogsProperty); }
set { SetValue(HideTitleBarForDialogsProperty, value); }
}

public static readonly DependencyProperty HideTitleBarForDialogsProperty =
DependencyProperty.Register("HideTitleBarForDialogs",
typeof(bool),
typeof(MainWindow),
new PropertyMetadata(true, ToggleHideTitleBarForDialogsPropertyChangedCallback));

private static void ToggleHideTitleBarForDialogsPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
var metroWindow = (MetroWindow)dependencyObject;
if (e.OldValue != e.NewValue)
{
var hideTitleBarForDialogs = (bool)e.NewValue;
metroWindow.ShowDialogsOverTitleBar = hideTitleBarForDialogs;
}
}

public bool UseAccentForDialogs
{
get { return (bool)GetValue(UseAccentForDialogsProperty); }
Expand Down