Closed Kartoffelsalat2 closed 4 years ago
I'm afraid I don't follow. What would you pass into this "parameter of type object"?
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.
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?
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.
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.
Okay, I guess I was a little lazy there. ;-)
:+1:
@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.
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.
@canton7 It works now. Thanks for fast reply and explanation. Keep going with excellent work.
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.