canton7 / Stylet

A very lightweight but powerful ViewModel-First MVVM framework for WPF for .NET Framework and .NET Core, inspired by Caliburn.Micro.
MIT License
990 stars 143 forks source link

Need a way to make the MessageBox more flexible. #120

Closed Kartoffelsalat2 closed 4 years ago

Kartoffelsalat2 commented 4 years ago

It would be great if the setup function of the MessageBox would have a parameter of type object. So you could design the MessageBox as you like.

canton7 commented 4 years ago

I'm afraid I don't follow. What would you pass into this "parameter of type object"?

Kartoffelsalat2 commented 4 years ago

If the MessageBox is used e.g. to display error messages, then you could give a picture to better describe the error. Or you could give the error code with this parameter to display it in a special format (e.g. bold and red). Or I could add some additional text and an info icon, where the text is shown as tooltip of the info icon.

canton7 commented 4 years ago

I don't get how allowing an extra object parameter lets the current MessageBox show all of these new things? Could you expand on this?

Kartoffelsalat2 commented 4 years ago

I have created my own customised MessageBox (as discribed here https://github.com/canton7/Stylet/wiki/MessageBox) where I implement the interface IMessageBoxViewModel and use my own View for this MessageBox. As I understood it, I can give all parameters which are available in the setup function declaration of IMessageBoxViewModel when calling windowManager.ShowMessageBox. If there would be another parameter of the type object, then I could design the MessageBox much more individual.

canton7 commented 4 years ago

To be honest, I'd write your own service (maybe subclass WindowManager, but probably just keep it separate) which has methods which take all of the parameters you need (and don't bother with IMessageBoxViewModel). That will be a lot cleaner than a random object parameter floating around.

Kartoffelsalat2 commented 4 years ago

Okay, I guess I was a little lazy there. ;-)

canton7 commented 4 years ago

:+1:

kezara commented 2 years ago

@canton7 Hi, I need help for customization of look of the message box. What I've tried: created CustomMessageBoxViewModel.cs which inherit Stylet.MessageBoxViewModel.cs and created my CustomMessageBoxView.xaml. CustomMessageBoxViewModel.cs is empty class since I don't want to change behavior. Then I register that as builder.Bind<IMessageBoxViewModel>().To<CustomMessageBoxViewModel>().InSingletonScope().AsWeakBinding(). When start application I get this exception: {"Multiple registrations found. Required by parameter 'messageBoxViewModelFactory' of type WindowManager (which is a Func<IMessageBoxViewModel>). Required by parameter 'windowManager' of type ShellViewModel (which is a IWindowManager)."} I'd appreciate any hint / help. Thanks.

canton7 commented 2 years ago

Remove the .AsWeakBinding() call.

The point of a weak binding is that it is ignored if there are any strong bindings. This allows Stylet to create weak bindings, and any strong bindings that you specify will replace them. However, if you create a second weak binding, that doesn't replace the first one: it just lives alongside it.

kezara commented 2 years ago

@canton7 It works now. Thanks for fast reply and explanation. Keep going with excellent work.