InfoBarMessageControl show errors from code

Topics: Questions
Jul 6, 2012 at 2:16 PM


is it possible to show the errors, which are shown at mouse over, from codebehind? Because I have an app where no mouse exists.

Jul 7, 2012 at 2:21 PM

Hmmm, interesting question. Internally, it uses the InfoBarMessageControl.generic.xaml style class. In there, there is a popup which visibility is bound like this:

<Popup IsOpen="{Binding ElementName=PART_MessageBar, Path=IsMouseOver, Mode=OneWay}" 
The simplest way to use this is to create a copy of the xaml code and link it in the resources yourself and remove this line of code. Then it is always visible as soon as there are any errors or warnings.

Jul 9, 2012 at 3:10 PM
Edited Jul 9, 2012 at 3:11 PM

Yes thanks, worked, but unfortunately there are many problems with it stayed open. First ist the position at window location moving. Fixed in codebehind. But still proplems. The popup remains in the front, even if the window is minimized or another window get focus.. Any suggestion to this? Maybe making a new control is the better way.

Jul 9, 2012 at 6:49 PM

The issue is that the popup is over the other windows. What you can do (but it might be very tricky), is to do the following:

1) Check the IsActive of the window the IBMC belongs to

2) If not active => hide, otherwise, show


But again, this is a hack, but still easier then writing your own control.

Jul 10, 2012 at 9:39 AM
Edited Jul 10, 2012 at 2:30 PM

My mistake...

Jul 10, 2012 at 11:01 AM
Edited Jul 10, 2012 at 1:02 PM

one more: I have set the DeferValidationUntilFirstSaveCall = true in my viewmodel. The ErrorTemplates are not called until save. Ok. But the InfoBarMessageControl still shows all errors from start on... What is my mistake?

Set it in the cnstuctor of my vm...

Jul 11, 2012 at 10:43 AM

Strange. The InfoBarMessageControl uses the ViewModel as it's data provider. Did you add a custom IBMC with a custom source? 

Jul 11, 2012 at 5:12 PM
Edited Jul 11, 2012 at 6:12 PM

No, have no custom source nor IBMC. Have just copied the geeneric style of the IBMC to my resources and changed icons, color, but not more. My validation is in the model, with overriding the validate methods. Maybe there is a problem?

I have a model property in my viewmodel, and when this is set with a model instance (what happens at startup), he starts to validate the complete model (why is the model validated, I thougt validating schould occur when a prop of the model itself changes). And then the IBMC gets the errors, and of course this model instance has at beginning no props set, I have for all props an error with a huge popup showing, beause I always show it...

At the moment I solved this with very ugly code; having a bool prop in my model which indicates if it is allowed to validate or not and set it to true if save is called...

By the way, what does the saving in the viewmodel really do? Do I have to override sth. to do saving? Or are the save() of the models called?

Jul 14, 2012 at 7:35 PM

Any suggestion here?

Jul 18, 2012 at 7:45 AM

Try using DeferValidationUntilFirstSaveCall property. I think that is what you need.

Jul 19, 2012 at 6:36 AM

? Have this already done. Wrote it in Post #6.

Jul 19, 2012 at 8:51 AM

Have you tried setting ValidateModelsOnItitialization to false in the view model constructor?

Jul 19, 2012 at 9:11 AM

Can you submit a repro? Then I can investigate it.