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

Custom dialogs DialogSettings #2775

Merged
merged 7 commits into from
Dec 22, 2016
Merged

Custom dialogs DialogSettings #2775

merged 7 commits into from
Dec 22, 2016

Conversation

punker76
Copy link
Member

What changed?

Some changes to fix #2735 MetroWindow.ShowMetroDialogAsync odd behaviour with provided DialogSettings

Closes #2735

@punker76 punker76 added this to the 1.4.0 milestone Dec 22, 2016
@punker76 punker76 changed the title Custom dialogs DialogSettings [WIP] Custom dialogs DialogSettings Dec 22, 2016
@@ -375,7 +406,8 @@ public static Task HideMetroDialogAsync(this MetroWindow window, BaseMetroDialog
{
window.RemoveDialog(dialog);

return HandleOverlayOnHide(settings,window);
settings = settings ?? dialog.DialogSettings;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ok, or should it be settings = settings ?? (dialog.DialogSettings ?? window.MetroDialogOptions);

Copy link
Collaborator

@thoemmi thoemmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

  ...with the new overloaded ShowMetroDialogAsync method
@punker76 punker76 changed the title [WIP] Custom dialogs DialogSettings Custom dialogs DialogSettings Dec 22, 2016
@punker76
Copy link
Member Author

punker76 commented Dec 22, 2016

It's now possible to do...

  • var customBaseMetroDialog = await this.ShowMetroDialogAsync<CustomBaseMetroDialog>();
    creates and shows a new custom dialog of the given type with the default dialog settings
  • var customBaseMetroDialog = await this.ShowMetroDialogAsync<CustomBaseMetroDialog>(this.metroDialogSettings);
    creates and shows also a new custom dialog of the given type with own settings

the custom dialog for this samples

<dialogs:CustomDialog x:Class="ShowMetroDialogAsyncIssue.CustomBaseMetroDialog"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" 
      d:DesignHeight="300" d:DesignWidth="300"
      Title="CustomBaseMetroDialog">
    <StackPanel>
        <TextBlock Text="This is a custom dialog based on BaseMetroDialog" />
        <Button Click="Close_OnClick">Close</Button>
    </StackPanel>
</dialogs:CustomDialog>
namespace ShowMetroDialogAsyncIssue
{
    using System.Windows;
    using MahApps.Metro.Controls;
    using MahApps.Metro.Controls.Dialogs;

    public partial class CustomBaseMetroDialog : CustomDialog
    {
        public CustomBaseMetroDialog()
        {
            InitializeComponent();
        }

        public CustomBaseMetroDialog(MetroDialogSettings settings) : base(settings)
        {
            InitializeComponent();
        }

        public CustomBaseMetroDialog(MetroWindow parentWindow, MetroDialogSettings settings) : base(parentWindow, settings)
        {
            InitializeComponent();
        }

        private void Close_OnClick(object sender, RoutedEventArgs e)
        {
            (this.OwningWindow ?? (MetroWindow)Application.Current.MainWindow).HideMetroDialogAsync(this);
        }
    }
}

Or

  • await this.ShowMetroDialogAsync(new CustomBaseMetroDialog());
    create and show custom dialog with default settings
  • await this.ShowMetroDialogAsync(new CustomBaseMetroDialog(this.metroDialogSettings)); or await this.ShowMetroDialogAsync(new CustomBaseMetroDialog(this, this.metroDialogSettings));
    create and show custom dialog with own settings

And..

It's possible to move the settings stuff to the custom dialog itself.

protected override MetroDialogSettings OnGetDialogSettings(MetroDialogSettings settings)
{
    return new MyCustomDialogSettings();
}

/cc @thoemmi

/// </summary>
/// <param name="settings"></param>
/// <returns></returns>
protected virtual MetroDialogSettings OnGetDialogSettings(MetroDialogSettings settings)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call this method ConfigureSettings. E.g. in ASP.NET you have methods like ConfigureServices, which allow you to intercept and add additional services. Here it allows the user to intercept and change the settings object.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx @thoemmi, naming is not my favorite ;-)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There two hard problems in computer science:

  • cache invalidation,
  • naming things, and
  • off-by-1 errors

😉

@punker76 punker76 merged commit 524c875 into develop Dec 22, 2016
@punker76 punker76 deleted the 2735-CustomDialog-Settings branch December 22, 2016 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

MetroWindow.ShowMetroDialogAsync odd behaviour with provided DialogSettings
2 participants