Skip to content

Commit

Permalink
Merge pull request #1050 from Amrykid/dialog-patch1
Browse files Browse the repository at this point in the history
MetroDialogs Patch #1
  • Loading branch information
AzureKitsune committed Feb 20, 2014
2 parents a99f480 + b059a52 commit 5d9b40a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
22 changes: 16 additions & 6 deletions MahApps.Metro/Controls/Dialogs/DialogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class DialogManager
public static Task<string> ShowInputAsync(this MetroWindow window, string title, string message, MetroDialogSettings settings = null)
{
window.Dispatcher.VerifyAccess();
return window.ShowOverlayAsync().ContinueWith(z =>
return HandleOverlayOnShow(settings, window).ContinueWith(z =>
{
return (Task<string>)window.Dispatcher.Invoke(new Func<Task<string>>(() =>
{
Expand Down Expand Up @@ -70,7 +70,7 @@ public static Task<string> ShowInputAsync(this MetroWindow window, string title,

window.metroDialogContainer.Children.Remove(dialog); //remove the dialog from the container

return window.HideOverlayAsync();
return HandleOverlayOnHide(settings, window);
//window.overlayBox.Visibility = System.Windows.Visibility.Hidden; //deactive the overlay effect

}))).ContinueWith(y3 => y).Unwrap();
Expand All @@ -91,7 +91,7 @@ public static Task<string> ShowInputAsync(this MetroWindow window, string title,
public static Task<MessageDialogResult> ShowMessageAsync(this MetroWindow window, string title, string message, MessageDialogStyle style = MessageDialogStyle.Affirmative, MetroDialogSettings settings = null)
{
window.Dispatcher.VerifyAccess();
return window.ShowOverlayAsync().ContinueWith(z =>
return HandleOverlayOnShow(settings, window).ContinueWith(z =>
{
return (Task<MessageDialogResult>)window.Dispatcher.Invoke(new Func<Task<MessageDialogResult>>(() =>
{
Expand Down Expand Up @@ -138,7 +138,7 @@ public static Task<MessageDialogResult> ShowMessageAsync(this MetroWindow window

window.metroDialogContainer.Children.Remove(dialog); //remove the dialog from the container

return window.HideOverlayAsync();
return HandleOverlayOnHide(settings, window);
//window.overlayBox.Visibility = System.Windows.Visibility.Hidden; //deactive the overlay effect

}))).ContinueWith(y3 => y).Unwrap();
Expand All @@ -148,6 +148,7 @@ public static Task<MessageDialogResult> ShowMessageAsync(this MetroWindow window
}));
}).Unwrap();
}

/// <summary>
/// Creates a ProgressDialog inside of the current window.
/// </summary>
Expand All @@ -160,7 +161,7 @@ public static Task<ProgressDialogController> ShowProgressAsync(this MetroWindow
{
window.Dispatcher.VerifyAccess();

return window.ShowOverlayAsync().ContinueWith(z =>
return HandleOverlayOnShow(settings, window).ContinueWith(z =>
{
return ((Task<ProgressDialogController>)window.Dispatcher.Invoke(new Func<Task<ProgressDialogController>>(() =>
{
Expand Down Expand Up @@ -207,7 +208,7 @@ public static Task<ProgressDialogController> ShowProgressAsync(this MetroWindow

window.metroDialogContainer.Children.Remove(dialog); //remove the dialog from the container

return window.HideOverlayAsync();
return HandleOverlayOnHide(settings, window);
//window.overlayBox.Visibility = System.Windows.Visibility.Hidden; //deactive the overlay effect
}));
}).Unwrap();
Expand All @@ -217,6 +218,15 @@ public static Task<ProgressDialogController> ShowProgressAsync(this MetroWindow
}).Unwrap();
}

private static Task HandleOverlayOnHide(MetroDialogSettings settings, MetroWindow window)
{
return (settings == null || settings.UseAnimations ? window.HideOverlayAsync() : Task.Factory.StartNew(() => window.Dispatcher.Invoke(new Action(() => window.HideOverlay()))));
}
private static Task HandleOverlayOnShow(MetroDialogSettings settings, MetroWindow window)
{
return (settings == null || settings.UseAnimations ? window.ShowOverlayAsync() : Task.Factory.StartNew(() => window.Dispatcher.Invoke(new Action(() => window.ShowOverlay()))));
}

/// <summary>
/// Adds a Metro Dialog instance to the specified window and makes it visible.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions MahApps.Metro/Controls/Dialogs/InputDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ private void Dialog_Loaded(object sender, RoutedEventArgs e)
{
case MetroDialogColorScheme.Accented:
this.PART_NegativeButton.Style = this.FindResource("HighlightedSquareButtonStyle") as Style;
PART_TextBox.SetResourceReference(ForegroundProperty, "BlackColorBrush");
break;
default:
break;
Expand Down
12 changes: 12 additions & 0 deletions MahApps.Metro/Controls/MetroWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,18 @@ public bool IsOverlayVisible()
{
return overlayBox.Visibility == Visibility.Visible && overlayBox.Opacity >= 0.7;
}
public void ShowOverlay()
{
overlayBox.Visibility = Visibility.Visible;
//overlayBox.Opacity = 0.7;
overlayBox.SetCurrentValue(Grid.OpacityProperty, 0.7);
}
public void HideOverlay()
{
//overlayBox.Opacity = 0.0;
overlayBox.SetCurrentValue(Grid.OpacityProperty, 0.0);
overlayBox.Visibility = System.Windows.Visibility.Hidden;
}

/// <summary>
/// Initializes a new instance of the MahApps.Metro.Controls.MetroWindow class.
Expand Down
2 changes: 1 addition & 1 deletion MahApps.Metro/Themes/Dialogs/InputDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
TextWrapping="Wrap"
Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType=Dialogs:InputDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Grid.Row="1"
Margin="0 0 0 0"
Margin="0 5 0 0"
FontSize="15"
x:Name="PART_TextBox"
Text="{Binding Input, RelativeSource={RelativeSource AncestorType=Dialogs:InputDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}"
Expand Down

0 comments on commit 5d9b40a

Please sign in to comment.