locked
Show a WPF window as a modal dialog in XBAP application RRS feed

  • Question

  • Hi there,

       I am developing an XBAP based application (Full trust) in which I need to show a modal dialog. For this, I created a window in xaml and designed my own MessageBox. I expose few APIs like 

    MyMessageBox.Show(string message) ;
    MyMessageBox.Show(string message, string caption); and so on...

    I actually use the API ShowDialog() to show the window (MessageBox). I use this API because it is a blocking call. 

    The problem I'm facing right now is when I use this message box in an XBAP application (Full Trust) the messagebox is displayed as a modeless dialog rather than a modal dialog. What exactly is causing this behavior. Am I missing something here? What I mean to say here is while the messagebox is displayed I'm still able to click on items on my page.



    Thanks,
    Ranjith
    Monday, March 8, 2010 7:50 AM

Answers

All replies

  • Hi ,

    There is an article introduces how create a modal dialog in XBAP application which may help you:


    ModalPopup Dialog in WPF Browser Applications (XBAP):

     


    Best day, Best life
    • Proposed as answer by Kira Qian Tuesday, March 9, 2010 3:21 AM
    • Marked as answer by Kira Qian Monday, March 15, 2010 7:53 AM
    Monday, March 8, 2010 8:22 AM
  • Hi,

        I intend to make use of the Window class itself. Can you help me understand how to achieve this? Btw, I see that the Win32 MessageBox.Show() method acts like a modal dialog then why not WPF window?

    Thanks,
    Ranjith
    Tuesday, March 9, 2010 7:46 AM
  • hi,

    You can design your own windows forms class with an ElementHost.  Therefore, you can also use the wpf to show your controls and form.
    I research your problem and find one reply is valuable: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/16985d54-b3fd-4025-9299-451bce7937a8/
    According to that reply, you may try to use popup to simulate a modal dialog. I'm sorry i knowledgeless on this issue.

    I wrote a simple sample about windows forms with an ElementHost, hope this helps:

    XAML:

    <Page x:Class="XBAPMessageBox.Page1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Page1">
        <Grid>
            <Button HorizontalAlignment="Center" VerticalAlignment="Center" Content="Click" Width="100" Click="Button_Click"/>
        </Grid>
    </Page>
    

    Bihind Code of XAML:
            private void Button_Click(object sender, RoutedEventArgs e)
            {
               
                Form1 myWindow = new Form1();
                myWindow.ShowDialog();
              
            }
    

    Windows.Forms form1 code:
     private void Form1_Load(object sender, EventArgs e)
            {
                System.Windows.Controls.TextBlock message = new System.Windows.Controls.TextBlock();
                message.Text = "Hello world";
    
                ElementHost wpfHost = new ElementHost();
                wpfHost.Dock = DockStyle.Fill;
                wpfHost.Child = message;
    
                this.Controls.Add(wpfHost);
            }

    Best day, Best life
    Tuesday, March 9, 2010 9:32 AM
  • Hello

     

    you can get part way on this, if you add to your XAMP Page the following

    <WindowsFormHost>

           <YOURWinformsUserControl x:Name="winformControl" />

    </WindowsFormHost>

     

    then when you open the window add the following

    new System.Window.Interop.WindowInteropHelper( YOURWPFWindowName ).Owner = winformControl.handle;

     

    now when you minimize the XBAP window the WPFWindow will also be minimized

    it is not perfect, but it is a step in the right direction

    Wednesday, June 12, 2013 5:06 PM
  • Please upload the correct URL.. This URL is broken

    Kartik Sukumaran

    Tuesday, February 18, 2014 11:54 AM