'Does anyone know how to override the XAML in the MahApps MessageDialog box?

I am trying to change the XAML used for the message text in the MessageDialog box. I can make the visual appearance change without issue, by redefining the ContentTemplate propery in my custom style as shown below, but when I do so, the buttons do not work.

<Style BasedOn="{StaticResource DetegoMetroDialogStyle}" TargetType="{x:Type dialogs:BaseMetroDialog}" />
    <Setter Property="ContentTemplate">
        <Setter.Value>
            <DataTemplate>
                <Grid Margin="0 10 0 0">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <ScrollViewer x:Name="PART_MessageScrollViewer"
                                  FocusVisualStyle="{x:Null}"
                                  Focusable="False"
                                  HorizontalScrollBarVisibility="Disabled"
                                  VerticalScrollBarVisibility="Auto">
                        <TextBlock x:Name="PART_MessageTextBlock"
                                   Margin="0 5 0 0"
                                   FontSize="{Binding DialogMessageFontSize, RelativeSource={RelativeSource AncestorType=Dialogs:MessageDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}"
                                   Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType=Dialogs:MessageDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}"
                                   
                                   FormattedTextBlock.FormattedText="{Binding Message, RelativeSource={RelativeSource AncestorType=Dialogs:MessageDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}"
                                   
                                   TextWrapping="Wrap" />
                    </ScrollViewer>

                    <StackPanel Grid.Row="1"
                                Height="85"
                                HorizontalAlignment="Right"
                                Orientation="Horizontal">
                        <Button x:Name="PART_AffirmativeButton"
                                Height="35"
                                MinWidth="80"
                                Margin="0 0 5 0"
                                Content="{Binding AffirmativeButtonText, RelativeSource={RelativeSource AncestorType=Dialogs:MessageDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}" />
                        <Button x:Name="PART_NegativeButton"
                                Height="35"
                                MinWidth="80"
                                Margin="5 0 5 0"
                                Content="{Binding NegativeButtonText, RelativeSource={RelativeSource AncestorType=Dialogs:MessageDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}" />
                        <Button x:Name="PART_FirstAuxiliaryButton"
                                Height="35"
                                MinWidth="80"
                                Margin="5 0 5 0"
                                Content="{Binding FirstAuxiliaryButtonText, RelativeSource={RelativeSource AncestorType=Dialogs:MessageDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}"
                                Visibility="Collapsed" />
                        <Button x:Name="PART_SecondAuxiliaryButton"
                                Height="35"
                                MinWidth="80"
                                Margin="5 0 0 0"
                                Content="{Binding SecondAuxiliaryButtonText, RelativeSource={RelativeSource AncestorType=Dialogs:MessageDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}"
                                Visibility="Collapsed" />
                    </StackPanel>
                </Grid>
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>

I assume that MessageDialog.xaml.cs is attaching the handlers to the buttons defined in the original style, rather than the overridden one.

Does anyone know of a solution to this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source