Own MessageService

Topics: Questions
Sep 17, 2012 at 10:05 AM


Have my own messageSevice. My MessageServiceEx derived from MessageService of catel.

Show() dims the backgroud calls base.Show() an Undimm the background. Now I wan't not to show a messagebox, but my own window.

How to do that?

Sep 17, 2012 at 11:32 AM

To dimm and undimm the window, use the EffectsHelper class.

You can use the UIVisualizerService or just call your custom window to show the actual window.

Sep 17, 2012 at 12:11 PM

The dimm and undimm is clear.

So you mean I can create an instance of my window in the messageservice and show it?

Sep 17, 2012 at 12:26 PM

Yes, the service is already separate from MVVM, so you can do anything there like showing the window like this:

var myWindow = new MyWindow();


Sep 17, 2012 at 12:37 PM

Ok. One more question:

Wan't to have a window with up to 3 Buttons. Use catel:DataWindow or Window as base class.

How can I set the buttons dynamicly and geht the result of the window.

Sep 17, 2012 at 12:39 PM

Create a property on the window with the actual WindowResult (DialogResult in WPF is just a bool?, so you will have to introduce your own enum value).

Sep 17, 2012 at 12:48 PM

catel:DataWindow or Window?

With catel:DataWindow i need also a viewModel is that correct?

Sep 17, 2012 at 12:49 PM

Yes, DW forces you to a view model, a normal window does not. Depends on your preference, I like the DW, but your requirements seem so simple that it should be no problem to use a regular window.

Sep 17, 2012 at 1:04 PM

So I use a regular window.

Add a ObservableCollection in the codebehind of the window and add the buttons there?

And set the WindowResult in the unloaded event?

Sep 17, 2012 at 1:05 PM

Again, what your preference is. This window will behave just like the messagebox, so it will not be used directly in MVVM scenarios, but always via the IMessageService. That's why you are free to do whatever you want, because during testing, etc you will use the test service.

The rest sounds good indeed.

Sep 17, 2012 at 1:14 PM

Yes I just wan't a messagebox with my one style.

It should be an easy solution. And i don't know what I need.

So you mean I just need a window with the codebehind as datacontext.

What's with the buttons, can I use the click event or do i have to implement commands.

Sorry for my questions but its not everything clear for me.

Sep 17, 2012 at 1:16 PM

Ok, the simplest thing to do is:

1) Create a custom Window (deriving from Window, not DataWindow)

2) Add your own buttons via the designer

3) Create a custom enum, MyMessageBoxResult (or re-use the existing MessageBoxResult)

4) When a button is clicked on the window (just link them via code-behind, keep it simple for now), set the MessageBoxResult on the window (a custom property)

5) Call this window in your custom message service.