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

Unable to change the MessageDialog highlighted button #2752

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

Unable to change the MessageDialog highlighted button #2752

DavidIQ opened this issue Nov 23, 2016 · 4 comments
Assignees
Milestone

Comments

@DavidIQ
Copy link

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
Copy link
Author

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
Copy link
Member

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

@DavidIQ
Copy link
Author

DavidIQ commented Nov 23, 2016

Great, thanks @punker76

@learnwithkharsh
Copy link

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
Labels
None yet
Development

No branches or pull requests

3 participants