punker76 / MahApps.Metro.SimpleChildWindow

A simple child window for MahApps.Metro
MIT License
374 stars 55 forks source link

Loaded event called twice? #123

Closed Josrph closed 2 years ago

Josrph commented 4 years ago

when calling ShowChildWindowAsync() my ContentControl Loaded event gets called twice ... it does not suppose to do that.

var view = new ContentControl();
view.Loaded += (s, arg) => 
{
    // gets called twice ???
};

var childWindow = new ChildWindow()
{
    ChildWindowWidth = 400,
    ChildWindowHeight = 300,
    ShowCloseButton = true,
    IsOpen = true,
    IsModal = true,
    Content = view,
};
await App.Current.MainWindow.ShowChildWindowAsync(childWindow);

PS: am using SimpleChildWindow version 1.5 with MahApps 1.6.5

punker76 commented 2 years ago

The Loaded event fires when an element becomes part of the visual tree. Depending where your element is, this can happen more than once. Also an application might have to recreate its visual tree.