This is a migrated thread and some comments may be shown as answers.

RibbonWindow: Loaded event strange behavior

1 Answer 63 Views
RibbonView and RibbonWindow
This is a migrated thread and some comments may be shown as answers.
Megamind
Top achievements
Rank 1
Megamind asked on 31 Mar 2019, 09:33 AM

According to normal behavior of WPF window, Loaded event occurs when the element is laid out, rendered, and ready for interaction.It is the last event raised in an element initialization sequence. Where as in RadRibbonWindow I have observed that the Loaded event is the first one to be called, even before the Window is shown at all. And when loaded event finished its work then Window appears on screen with all its content loaded. This behavior confuses with the description of Loaded event here  https://docs.microsoft.com/en-us/dotnet/api/system.windows.frameworkelement.loaded?redirectedfrom=MSDN&view=netframework-4.7.2 ?

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 02 Apr 2019, 07:01 AM
Hello Megamind,

Actually, MSDN is a bit inconsistent when it comes to the Loaded event. The article you pointed out (FrameworkElement.Loaded Event), tells that when the Loaded event is fired the control is already rendered. On the other hand the Object Lifetime Events article tells that the Loaded fires just before the rendering. Which is also my observation from my experience with WPF. In addition, during the last a couple of years I've hit few topics over the internet on this topic, and it seems that when the Loaded event is fired, the corresponding control is already measured and arranged, and waits to be rendered.

Moreover, the RadRibbonWindow derives from the native Window control, which derives from FrameworkElement, where the Loaded events is coming from. In other words, the WPF frameworks is taking care for the Loaded event and there is not much that can be done to alter this.

If you want to execute something after the window is rendered you can schedule a new action to be execute (in the Loaded event handler) on the next layout pass which probably would be the moment when the window is rendered. 
private void RadRibbonWindow_Loaded(object sender, RoutedEventArgs e)
{
    Dispatcher.BeginInvoke(new Action(() => {
        // execute some logic here
    }));
}
You can try with different DispatcherPriority. This is the second parameter of the BeginInvoke() method.

I hope this information helps. 

Regards,
Martin Ivanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
RibbonView and RibbonWindow
Asked by
Megamind
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or