views:

58

answers:

1

I have an object that in a simplified form is as follows:

public class MyObject
{
     public bool Activate { 
     get { MessageBox.Show("My Status"); } 
     set { Do Some Stuff }
}

I have a DataTemplate that maps the "Activate" property to a check box like so:

<DataTemplate x:Key="ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type clr:Boolean}}">
      <CheckBox IsEnabled="{Binding Path=IsWriteable}" IsChecked="{Binding Path=Value}"/>
</DataTemplate>

The template is from the WPF Property Grid control that I'm using. The issue is that the message box is never shown and the main window is waiting for a response from the box. I hear the error notification sound when the call is expected but no dialog is present.

Is there something in WPF that changes the z-order? Am I running in a context I'm not expecting?

+1  A: 

You should never show a messagebox inside a getter! Use commands instead.

If you pass the MessageBox.Show call the current window as a parameter, it should be displayed modal.

winSharp93
Tried it with commands and it still does the same thing. Command is bound in XAML on the main window. The command is then executed from within the property above. The event handler for execute is called and a MessageBox.Show is found within the handler. I hear the sound of the dialog presenting itself but it is not displayed. Any ideas?
Adam Driscoll
Why are you executing the command in the getter? Let the WPF execute it by using one of the solutions you will find via google to map commands to events.
winSharp93
What I really was looking for was validation handling. Thanks for trying to help and sorry for being stubborn.
Adam Driscoll