Calling close on Loaded event cause exception

Ribbon for WPF Forum

Posted 11 years ago by Anurodh Ora
Avatar
Hi,

Run time exception occurring when we call Close on loaded event.

Test scenario:
1) Have two ribbon windows(say R1 and R2).
2) Place a button(say Create) in R1 and on click event place following code

     R2 window = new R2();
     window.ShowDialog();
3) On Loaded event of R2 place following code

     this.Close();
4) In App.xaml set StartupUri="R1.xaml"
5) Run the application and click on Create. Notice the run time exception.

Note: Above scenario works fine if we use R2 as normal wpf window.

Is this a bug / are we doing something wrong here / any workaround ?

Thanks and Regards,
Anurodh

[Modified at 12/08/2008 12:31 AM]

Comments (11)

Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Anurodh,

Can you please email our support address with your simple sample project that shows this and in your email reference this post? Thanks!


Actipro Software Support

Posted 11 years ago by Anurodh Ora
Avatar
Hi,

Mailed the sample please have a look at it. Please see inline comments in the code to get more information.

Thanks and Regards,
Anurodh
Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks for the sample, the fix is in the build 481 release we just posted.


Actipro Software Support

Posted 11 years ago by Anurodh Ora
Avatar
Hi,

Thanks for the fix.

But on installing new build we are seeing very strange behavior with our current application.
The main screen which is ribbon window (and which opens in maximized state) on application launch is now flickering for 2-3 times. And randomly on menu/tab click.

Could you please look into this.

Thanks and regards,
Anurodh
Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Please give us more information on this flicker. What operating system do you run, is your computer 32 or 64-bit, and what system theme is active?

Also do you have glass enabled if in Vista?

Did this also happen in the previous build?


Actipro Software Support

Posted 11 years ago by Anurodh Ora
Avatar
Hi,

We are running Windows XP with WindowsXP theme (color scheme-Blue) and on 32bit machine.
And the application was working fine with previous build.

You can see the same effect if you modify the sample sent by me on this as below:
1) Open RibbonWindow1.xaml
2) Delete ResizeMode="NoResize"
3) and in place Insert WindowState="Maximized"

And notice the flicker.

Resolution is 1024x768 pixels.

Thanks and Regards,
Anurodh

[Modified at 12/11/2008 09:48 AM]
Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
We have a fix for this. We'll try and get it out tomorrow or on Monday at the latest.


Actipro Software Support

Posted 11 years ago by Anurodh Ora
Avatar
Hi,

We are seeing the same behavior "Calling close on Loaded event cause exception" with the latest build posted - 482. You can run the sample sent by me on this issue on the new build to check the behavior

Could you please have a look into it.

Thanks and Regards,
Anurodh
Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Anurodh,

I see now... we had previously reproduced it with Vista and glass active, the fix resolved that. But apparently it didn't help with when glass is not active.

Now that I debug in glass-not-active mode, the exception actually fires from Microsoft's code and is different than the area we fixed before. What happens is that the RibbonWindow.SourceInitialized event fires, in which we alter the border style of the window to None. This apparently triggers the Loaded event via Microsoft's code and since you close it in that method, another Microsoft internal handler blows up. There's nothing we can really do about that since it's not in our code.

Here is a workaround you can do though. Instead of calling this.Close in the middle of this sequence of events, invoke it like this:
private void RibbonWindow_Loaded(object sender, RoutedEventArgs e) {
    this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, 
        (System.Windows.Threading.DispatcherOperationCallback)delegate { 
            this.Close();
            return null;
        }, null);
}
The problem doesn't happen in that case since it gets closed immediately after the Loaded event.


Actipro Software Support

Posted 11 years ago by Anurodh Ora
Avatar
Thanks for the reply.

We used above code and it works fine but the window which is to be closed does not go immediately and you can see the window first appearing and then disappearing.

We do not want the window to appear/disapper. What we can do to prevent this behavior?

Regards,
Anurodh
Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
We did manage to find another thing you can do instead. Set WindowStyle="None" in your XAML for RibbonWindow2. That works around the bug in Microsoft's code which is throwing this exception.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.