Custom dialogs DialogSettings #2775

Merged
merged 7 commits into from Dec 22, 2016

Conversation

Projects
None yet
2 participants
@punker76
Member

punker76 commented Dec 22, 2016

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 from Custom dialogs DialogSettings to [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;

This comment has been minimized.

@thoemmi

thoemmi Dec 22, 2016

Collaborator

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

@thoemmi

thoemmi Dec 22, 2016

Collaborator

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

@thoemmi

Looks good to me

Now it's possible to create custom dialogs with own settings
  ...with the new overloaded ShowMetroDialogAsync method

@punker76 punker76 changed the title from [WIP] Custom dialogs DialogSettings to Custom dialogs DialogSettings Dec 22, 2016

@punker76

This comment has been minimized.

Show comment
Hide comment
@punker76

punker76 Dec 22, 2016

Member

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

Member

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)

This comment has been minimized.

@thoemmi

thoemmi Dec 22, 2016

Collaborator

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.

@thoemmi

thoemmi Dec 22, 2016

Collaborator

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.

This comment has been minimized.

@punker76

punker76 Dec 22, 2016

Member

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

@punker76

punker76 Dec 22, 2016

Member

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

This comment has been minimized.

@thoemmi

thoemmi Dec 22, 2016

Collaborator

There two hard problems in computer science:

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

😉

@thoemmi

thoemmi Dec 22, 2016

Collaborator

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

1 check passed

continuous-integration/teamcity Finished TeamCity Build MahApps.Metro PullRequest :: MahApps.Metro PullRequests : Tests passed: 62
Details

@punker76 punker76 deleted the 2735-CustomDialog-Settings branch Dec 22, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment