After writing comment to Zane's post, a after thought came to me: actually you dont want to use such solution with boolean flag, or you must make it even more robust.
It cames to be, that a Control may be REUSED. This means, that the control may be added to tree, then removed, then added, then removed and so on. If you really need to filter out the multiple invocations of Loaded, you must track the Unloaded event, too!
Following Zane's example, it should resemble following code:
using System.Windows;
using System.Windows.Controls;
public class LoadOnceUserControl : UserControl
{
private bool firstLoadCalled = false;
public LoadOnceUserControl()
{
this.Unloaded += (sender,e) => firstLoadCalled = false;
this.Loaded += (sender,e) =>
{
if (this.firstLoadCalled) return;
this.firstLoadCalled = true;
var copy = this.FirstLoaded;
if (copy != null) copy(sender,e);
});
}
/*public*/ event RoutedEventHandler FirstLoaded;
}
Please note that it also could be reasonable to add analogous FirstUnloaded just for symmetry. I have never seen it called spuriously though.
And mind that despite waht I wrote in comment to Zane's - in this approach you should not detach that handlers