This project is read-only.

Style Property Suggestion

Aug 10, 2012 at 7:47 PM
Edited Aug 10, 2012 at 8:05 PM

Added the following (highlighted in red) to the Show method in WPFMessageBoxWindow.xaml.cs to my local copy of the source code:

public static MessageBoxResult Show(           
            Action setOwner,
            string messageBoxText,
            string caption,
            Style style,
            MessageBoxButton button,
            MessageBoxImage icon,
            MessageBoxResult defaultResult,
            MessageBoxOptions options)
            if ((options & MessageBoxOptions.DefaultDesktopOnly) == MessageBoxOptions.DefaultDesktopOnly)
                throw new NotImplementedException();

            if ((options & MessageBoxOptions.ServiceNotification) == MessageBoxOptions.ServiceNotification)
                throw new NotImplementedException();

            _messageBoxWindow = new WPFMessageBoxWindow();

            if (style != null)
                _messageBoxWindow.Resources.Add(typeof(WPFMessageBoxControl), style);



            _messageBoxWindow._viewModel = new MessageBoxViewModel(_messageBoxWindow, caption, messageBoxText, button, icon, defaultResult, options);
            _messageBoxWindow.DataContext = _messageBoxWindow._viewModel;
            return _messageBoxWindow._viewModel.Result;

And then in my application I added the following class:

public static class MessageBoxStyle
        public static Style None = null;
        public static Style Default = null;
        public static Style Silly = null;

        static MessageBoxStyle()
            Default = (Style)App.Current.TryFindResource("MessageBoxDefault");
            Silly = (Style)App.Current.TryFindResource("MessageBoxSilly");

I can now call the WPFMessageBox in the following manner to dynamically get any look I want:

WPFMessageBox.Show("message", "caption", MessageBoxStyle.Silly, MessageBoxButton.OK, MessageBoxImage.Error);

It works great and I really like the new flexibility. Let me know what you think and maybe someone can get it added.

Aug 10, 2012 at 8:05 PM

I also add a default style in the WPFMessageboxWindow.xaml file. Hence the call to the Resources.Clear( ) method.