Modern Dialog Buttons

May 22, 2013 at 12:57 PM
Hi,

how to define the buttons in Modern Dialog?

I have a close button. I want to have a OK button.

Please help.

Thanks.
May 30, 2013 at 7:58 AM
Anyone?
May 31, 2013 at 1:50 AM
baltazar_oliveira wrote:
Hi,

how to define the buttons in Modern Dialog?

I have a close button. I want to have a OK button.

Please help.

Thanks.
Try to use ModernDialog.ShowMessage(), in which you can set Buttons.
May 31, 2013 at 7:48 AM
I need a dialog, not a message.
Jun 19, 2013 at 8:48 AM
Edited Jun 19, 2013 at 8:49 AM
Can anyone answer this?

I need a ModernDialog with the ability to select Yes or OK which gives a dialogresult=true and the standard Cancel which gives a dialogresult=false, I cant seem to see where it can be set.

Thank you.
Jun 19, 2013 at 9:03 PM
First solution:
using System.Windows;
using System.Windows.Controls;
using GalaSoft.MvvmLight.Command;

namespace ModernUIApp1 {

    public partial class Dialog {

        public Dialog() {
            InitializeComponent();

            Buttons = new[] {
                OkButton, CancelButton,
                new Button {
                    Content = "Foo",
                    Command = Foo,
                    IsDefault = false,
                    IsCancel = false,
                    MinHeight = 21,
                    MinWidth = 65,
                    Margin = new Thickness(4, 0, 0, 0)
                }
            };

            Foo = new RelayCommand(() => { /* something */ });
        }

        private RelayCommand Foo { get; set; }
    }
}
<mui:ModernDialog x:Class="ModernUIApp1.Dialog" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mui="clr-namespace:FirstFloor.ModernUI.Windows.Controls;assembly=FirstFloor.ModernUI"
        Title="Dialog" Height="300" Width="300">

    <Grid>
        <TextBlock>Content</TextBlock>
    </Grid>
</mui:ModernDialog>
Jun 19, 2013 at 9:25 PM
Edited Jun 20, 2013 at 7:58 PM
Second Solution:
using GalaSoft.MvvmLight.Command;

namespace ModernUIApp1 {

    public class ButtonList : List<Button> { }

    public partial class Dialog {

        public Dialog() {
            InitializeComponent();

            Foo = new RelayCommand(() => { /* something */ });
        }

        private RelayCommand Foo { get; set; }
    }
}
<mui:ModernDialog x:Class="ModernUIApp1.Dialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mui="http://firstfloorsoftware.com/ModernUI"
        xmlns:modernUiApp1="clr-namespace:ModernUIApp1" Title="Dialog" Height="300" Width="300"
        DataContext="{Binding RelativeSource={RelativeSource Self}}">

    <mui:ModernDialog.Resources>
        <Style TargetType="Button">
            <Setter Property="Margin" Value="4,0,0,0" />
            <Setter Property="MinHeight" Value="21" />
            <Setter Property="MinWidth" Value="65" />
        </Style>
    </mui:ModernDialog.Resources>
    
    <mui:ModernDialog.Buttons>
        <modernUiApp1:ButtonList>
            <Button Content="OK" Command="{Binding CloseTrueCommand}" IsDefault="True" />
            <Button Content="Close" Command="{Binding CloseCommand}" IsCancel="True" />
            <Button Content="Foo" Command="{Binding Foo}" />
        </modernUiApp1:ButtonList>
    </mui:ModernDialog.Buttons>

    <Grid>
        <TextBlock>Content</TextBlock>
    </Grid>
</mui:ModernDialog>
It works, but it's kind of a hack. (VS2012 is complaining about ButtonList, nevertheless it will do.) I'd appreciate direct support in m:ui.
Also, if you are happy with the built in buttons, they are not localizable via XAML. You need the sources of m:ui adding a Resources.xx.resx
Jul 2, 2013 at 8:34 PM
Sorry, but this is no good, because it is a hack....oh, and where the heck does GalaSoft.MvvmLight.Command come from?

The ability to set which buttons appear on a moderndialog must be available within the Modern UI framework, without using external coding.

I would have thought this would be a simple exercise given the amount of effort that has already gone into producing this framework.

An example snippet in a code behind would be something like:-
ModernDialog MyDiag = new ModernDialog();
        MyDiag.Title = "Customer Search";
        MyDiag.Content = new CustomerSearchDialog();
        MyDiag.Buttons = Buttons.YesNoCancel; -or- whatever combinations that are possible, YesCancel, NoCancel, OkCancel, Cancel, No, Yes, etc, etc....
        MyDiag.ShowDialog();

Currently, all we get is the Close button.

Is this that hard to incorporate within the framework?

Thank you for listening.
Jul 3, 2013 at 7:54 AM
I have remove all buttons. I have created in "EnvioEmail" the buttons that i want.
List<System.Windows.Controls.Button> list = new List<System.Windows.Controls.Button>();
                Collection<System.Windows.Controls.Button> collection = new Collection<System.Windows.Controls.Button>(list);

                new ModernDialog
                {
                    Title = "Envio E-Mail",
                    Content = new EnvioEmail(),
                    Buttons = collection
                }.ShowDialog();
Jul 4, 2014 at 11:49 AM
Hi all,

I know this is an old thread, but I have this problem now, and already fixed.

In downloaded the source code of the Modern UI project, and added this method to FirstFloor.ModernUI.Windows.Controls.ModernDialog.cs class:
        /// <summary>
        /// Displays a custom messagebox.
        /// </summary>
        /// <returns></returns>
        public MessageBoxResult ShowModernDialog()
        {
            this.ShowDialog();
            return this.dialogResult;
        }
Then you can easily customize your message:
            ModernDialog dialog = new ModernDialog();
            dialog.Content = dialogContent.Content;
            dialog.Title = "Opciones";
            dialog.OkButton.Content = "Continuar";
            dialog.CancelButton.Content = "Cancelar";
            dialog.Buttons = new[] {
                dialog.OkButton, dialog.CancelButton,
            };
("dialogContent" is a hidden ContentControl created in ViewModel for ease) :p

And finaly you can receive the dialog result as in Windows Forms:
MessageBoxResult result = dialog.ShowModernDialog();
And do your stuff with the dialogContent.Content (i.e. checkboxes, textboxes).

I hope this can help someone.

Cheers.