Thursday, August 28, 2008

WPF Window Events - Loaded or Initialized?

So I was trying to determine which event to use for handling window initialization in WPF, since there seems to be a couple of options that are a little different from Windows Forms: Initialized and Loaded.

Thankfully MSDN came to the rescue and clarified things a bit in the documentation for the Initialized event:
[Initialized] will be raised whenever the EndInit or OnVisualParentChanged methods are called. Calls to either method could have come from application code, or through the Extensible Application Markup Language (XAML) processor behavior when a XAML page is processed.

Whether you choose to handle Loaded or Initialized depends on your requirements. If you do not need to read element properties, intend to reset properties, and do not need any layout information, Initialized might be the better event to act upon. If you need all properties of the element to be available, and you will be setting properties that are likely to reset the layout, Loaded might be the better event to act upon. Be careful of reentrancy if your handler resets any properties that are interpreted by the layout system to mean that a new layout pass is required. (You might need to check the FrameworkPropertyMetadata values on the property if you are unsure of which properties can require a new layout pass if they are changed.)

Tuesday, August 5, 2008

Disabling Windows Desktop Search Explorer Integration

If anyone hates the steaming turd that is Windows Desktop Search's Explorer Integration as much as I do (i.e. the search utility that can't find anything), please read Scott Hanselman's blog article outlining the very simple fix to disable this piece of total crap software:

Scott Hanselman's Computer Zen - How to disable Windows Desktop Search explorer integration after installing Office 2007

I feel much better now.

Hope this helps!