Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ribbonwindow crashes #178

Closed
bochelie1000 opened this issue Oct 13, 2015 · 12 comments
Closed

Ribbonwindow crashes #178

bochelie1000 opened this issue Oct 13, 2015 · 12 comments
Assignees
Labels
Milestone

Comments

@bochelie1000
Copy link

I use a ribbonwindow. After my window is loaded I generate an error (in the window Loaded method). In the catch statement i try to show a messagebox to show the error code. But everything crashes.
If i put the code just after the Initialize metbod of the window then everything is ok. I think this is a critical bug.

To avoid this problem I must use a normal window with the ribbon in it and avoid the RibbonWinow. However this is not as beautifull as the RibbonWindow.

@batzen
Copy link
Member

batzen commented Oct 13, 2015

Could you create a small repro for your issue?
Adding your code to the TestWindow in the showcase application and posting the code here would be enough for a small repro.
I tried to reproduce your issue by subscribing to the loaded event and showing a MessageBox when it's fired. Everything worked as expected.

@bochelie1000
Copy link
Author

I try to reproduce the error but it is difficult without luck. I make use of threads in my application, which makes it difficult to reproduce. I will keep trying to reproduce the error. I dont think there is something wrong with my application because it only happens with the RibbonWindow. Everything works fine if I use a normal window.
Crazy is that the application does not give an error it just closes.

@bochelie1000
Copy link
Author

By the way the messagebox is a window i made myself. And the error only occurs when i try to show the window with ShowDialog().
I get this error: Cannot perform this operation while dispatcher processing is suspended.
I can solve it by calling the window or messagebox thrue the dispatcher: Dispatcher.BeginInvoke(new Action(() => MessageBox.Show("Test")));

This is a workaround. However I would like to know why this happens only with the RibbonWindow.

I still cant reproduce the error. However it is still there in my Application.

@bochelie1000
Copy link
Author

I started looking for the problem myself in the FluentRibbon source code. And found that the code always blocks here:
private void UpdateWindowChrome()
{
var windowChrome = WindowChrome.GetWindowChrome(this);

        if (windowChrome == null)
        {
            windowChrome = new WindowChrome();
            WindowChrome.SetWindowChrome(this, windowChrome);
        }

        windowChrome.CaptionHeight = RibbonProperties.GetTitleBarHeight(this);
        windowChrome.CornerRadius = this.CornerRadius;
        windowChrome.GlassFrameThickness = this.GlassBorderThickness;
        windowChrome.ResizeBorderThickness = this.ResizeBorderThickness;

#if NET45
windowChrome.UseAeroCaptionButtons = this.CanUseDwm;
#endif
}

Then specialy in this row: WindowChrome.SetWindowChrome(this, windowChrome);

I cant debug the code from this line on. If I knew how than I would do it. Maybe someone have an idea?

@bochelie1000
Copy link
Author

It seems like the above method is called twice. If I neglect the the SetWindowChrome method the first time than everything works fine.

However I miss some pieces of the style. For example the close and open
However I would like to know more and resolve the real issue. Who has any ideas?

This is my new workaround:

    private bool _isScndTime;
    private void UpdateWindowChrome()
    {
        var windowChrome = WindowChrome.GetWindowChrome(this);

        if (windowChrome == null)
        {
            windowChrome = new WindowChrome();
           if(_isScndTime) WindowChrome.SetWindowChrome(this, windowChrome);
        }
        _isScndTime = true;

        windowChrome.CaptionHeight = RibbonProperties.GetTitleBarHeight(this);
        windowChrome.CornerRadius = this.CornerRadius;
        windowChrome.GlassFrameThickness = this.GlassBorderThickness;
        windowChrome.ResizeBorderThickness = this.ResizeBorderThickness;

#if NET45
windowChrome.UseAeroCaptionButtons = this.CanUseDwm;
#endif
}

However I would like to know more and resolve the real issue. Who has any ideas?

@batzen
Copy link
Member

batzen commented Oct 15, 2015

So WindowChrome.GetWindowChrome(this) returns null in your application?
It should only return null on the first call of UpdateWindowChrome and it does exactly that in the showcase application.

Do you reset that property somewhere?

@bochelie1000
Copy link
Author

No. That is not the problem.
WindowChrome.GetWindowChrome(this) does return null the first time. If i ignore it the first time, than it works.
I dont reset this property anywhere. I think maybe it try to make a call that my ShowDialog is also doong. However the window i try to show is conpletly empty. There is no code in it.

@bochelie1000
Copy link
Author

I finaly could reproduce the error. Look in the link below for the WpfApplication2 zip.

There is also a second bug. If you go to the code behind the main window and remove the line : w1.ShowDialog(); than it wil start ok. But than try to maximize the window. You will notice that the window does crazy things when maximizing.

link: https://onedrive.live.com/redir?resid=DA6ABE46D5BCE7BE!229&authkey=!AGqpWr6bJqSH004&ithint=file%2crar

@batzen
Copy link
Member

batzen commented Oct 17, 2015

Will have a look at your repro next week.

@batzen
Copy link
Member

batzen commented Oct 21, 2015

Can't download your repro, onedrive just tells me something went wrong.

@bochelie1000
Copy link
Author

Strange, i just tried and it worked.
I put it in my google drive as well. You can try this link: https://drive.google.com/folder/d/0Bz2GgnJ4oZh1R3dMYnN5d2RNTjg/edit

@batzen
Copy link
Member

batzen commented Oct 22, 2015

Ok, pretty simple.
WPF runs into OnApplyTemplate of the RibbonWindow where UpdateWindowChrome is called, when calling WindowChrome.SetWindowChrome(this, windowChrome); the dispatcher seems to stop execution of the current method and raises the loaded event.

Solution: I will remove the call to UpdateWindowChrome in OnApplyTemplate because the WindowChrome is updated as soon as OnSourceInitialized is called on the RibbonWindow.

@batzen batzen closed this as completed in 97001b1 Oct 22, 2015
@batzen batzen added this to the Next milestone Oct 22, 2015
@batzen batzen self-assigned this Oct 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants