views:

162

answers:

1

Anyone got any neat solutions to prevent a Silverlight ChildWindow being moved?

thanks, Mark

A: 

I'm not sure you'd call this neat but...

  • Create yourself a new Templated control and call it ImmovableChildWindow.
  • Modify the class it inherits from to be ChildWindow.
  • Open Themes/generic.xaml you will find an initial style for the ImmoveableChildWindow
  • In the Silverlight documentation you'll find the existing template for a ChildWindow at ChildWindow Styles and Templates.
  • Note the existing TargetType value for the ImmovableChildWindow style.
  • Copy'n' paste the whole default style for a ChildWindow from the documentation into your themes/generic.xaml file.
  • Replace TargetType for this copy to the same value as the exiting ImmovaleChildWindow style.
  • You can now delete the initial style. Leave only the large copy of ChildWindow style now targeting ImmovableChildWindow.
  • Find within the Template setter change the TargetType of to the same value as the style TargetType
  • Search through the template and find a Border with the name Chrome. Delete the x:Name="Chrome" attribute. (This is what we are really after).

Now when you create a new ChildWindow item it will by default inherit form ChildWindow, if you want it to be immovable you need modify it to inherit from ImmovableChildWindow instead (change the base type in the code-behind and the root tag name in the xaml).

The ChildWindow attaches events to the FrameWorkElement with the name "Chrome" which enables the child window to be moved about. However being a well-behaved templated control, if it can't find a FrameworkElement called "Chrome" it just continues to work without that feature.

AnthonyWJones