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

Unable to change the MessageDialog highlighted button #2752

Closed
DavidIQ opened this Issue Nov 23, 2016 · 4 comments

Comments

Projects
None yet
3 participants
@DavidIQ

DavidIQ commented Nov 23, 2016

What steps will reproduce this issue?

Set DefaultButtonFocus to something other than the Affirmative button for MessageDialogSettings and call the MetroWindow's ShowMessageAsync.

Expected outcome

Highlighted button is set to the default button. Why? Because users are under the impression that the highlighted button is what will be selected when they hit the Enter key. This does not seem to be something that can be overridden though:
https://github.com/MahApps/MahApps.Metro/blob/develop/src/MahApps.Metro/MahApps.Metro/Themes/Dialogs/MessageDialog.xaml#L35
Other than making the Affirmative button look like the others there doesn't appear that I can do much of anything else to the style to highlight the actual default button.

--

Environment

  • MahApps.Metro v1.3.0
  • Windows 10
  • Visual Studio 2015
  • .NET Framework 4.5.2

@punker76 punker76 self-assigned this Nov 23, 2016

@punker76 punker76 added this to the 1.4.0 milestone Nov 23, 2016

@DavidIQ

This comment has been minimized.

Show comment
Hide comment
@DavidIQ

DavidIQ Nov 23, 2016

For now this is what I have come up with, which seems to be working as desired:

Create a ResourceDictionary file with the following:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
                    xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls">

    <Style BasedOn="{StaticResource SquareButtonStyle}" TargetType="{x:Type Button}">
        <Setter Property="controls:ControlsHelper.ContentCharacterCasing" Value="Normal" />
        <Style.Triggers>
            <Trigger Property="IsFocused" Value="True">
                <Setter Property="Foreground" Value="{DynamicResource IdealForegroundColorBrush}" />
                <Setter Property="Background" Value="{StaticResource AccentColorBrush}" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="AccentedDialogSquareButton"
           BasedOn="{StaticResource SquareButtonStyle}"
           TargetType="{x:Type ButtonBase}">
        <Setter Property="controls:ControlsHelper.ContentCharacterCasing" Value="Normal" />
        <Style.Triggers>
            <Trigger Property="IsFocused" Value="True">
                <Setter Property="Foreground" Value="{DynamicResource IdealForegroundColorBrush}" />
                <Setter Property="Background" Value="{StaticResource AccentColorBrush}" />
            </Trigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>

Then load the resource into the MetroDialogSettings object that is being passed to the ShowMessageAsync method:

dialogSettings.CustomResourceDictionary = new ResourceDictionary { Source = new System.Uri("pack://application:,,,/ComponentsProject;component/Themes/Components.MetroMessageBox.xaml") };
var result = await metroWindow.ShowMessageAsync(caption, message, dialogStyle, dialogSettings);

@punker76 Might have been better to post this at StackOverflow maybe, unless you still feel this should be something in the base.

DavidIQ commented Nov 23, 2016

For now this is what I have come up with, which seems to be working as desired:

Create a ResourceDictionary file with the following:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
                    xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls">

    <Style BasedOn="{StaticResource SquareButtonStyle}" TargetType="{x:Type Button}">
        <Setter Property="controls:ControlsHelper.ContentCharacterCasing" Value="Normal" />
        <Style.Triggers>
            <Trigger Property="IsFocused" Value="True">
                <Setter Property="Foreground" Value="{DynamicResource IdealForegroundColorBrush}" />
                <Setter Property="Background" Value="{StaticResource AccentColorBrush}" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="AccentedDialogSquareButton"
           BasedOn="{StaticResource SquareButtonStyle}"
           TargetType="{x:Type ButtonBase}">
        <Setter Property="controls:ControlsHelper.ContentCharacterCasing" Value="Normal" />
        <Style.Triggers>
            <Trigger Property="IsFocused" Value="True">
                <Setter Property="Foreground" Value="{DynamicResource IdealForegroundColorBrush}" />
                <Setter Property="Background" Value="{StaticResource AccentColorBrush}" />
            </Trigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>

Then load the resource into the MetroDialogSettings object that is being passed to the ShowMessageAsync method:

dialogSettings.CustomResourceDictionary = new ResourceDictionary { Source = new System.Uri("pack://application:,,,/ComponentsProject;component/Themes/Components.MetroMessageBox.xaml") };
var result = await metroWindow.ShowMessageAsync(caption, message, dialogStyle, dialogSettings);

@punker76 Might have been better to post this at StackOverflow maybe, unless you still feel this should be something in the base.

@punker76

This comment has been minimized.

Show comment
Hide comment
@punker76

punker76 Nov 23, 2016

Member

@DavidIQ The style is now set to the selected default button in code behind. Available in 1.4.0

Member

punker76 commented Nov 23, 2016

@DavidIQ The style is now set to the selected default button in code behind. Available in 1.4.0

@DavidIQ

This comment has been minimized.

Show comment
Hide comment
@DavidIQ

DavidIQ commented Nov 23, 2016

Great, thanks @punker76

@Kumar2Harsh

This comment has been minimized.

Show comment
Hide comment
@Kumar2Harsh

Kumar2Harsh Apr 25, 2018

var metroDialogButton = new MetroDialogSettings()
{
DefaultButtonFocus=MessageDialogResult.Affirmative
};

Kumar2Harsh commented Apr 25, 2018

var metroDialogButton = new MetroDialogSettings()
{
DefaultButtonFocus=MessageDialogResult.Affirmative
};

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