Mark Cooper
Mark Cooper

Reputation: 6894

Silverlight - preventing ChildWindow movement

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

thanks, Mark

Upvotes: 0

Views: 1523

Answers (3)

Ravi
Ravi

Reputation: 11

Not Required to Create new class, instead

  1. Copy the style from: http://msdn.microsoft.com/en-us/library/dd833070%28VS.95%29.aspx

  2. Give x:key="stylename"

  3. In Construtor of Childwindow, paste following code before InitializeComponent:

    this.Style = App.Current.Resources["childWindow"] as Style;

above solution resolved my issue

Upvotes: 1

Mrainy
Mrainy

Reputation: 65

Maybe you can try this simple way to do that: Create a Grid to warp all the content in your ChildWindow.

<Grid Margin="0">

<!--Your ChildWindow. Canvas, Grid, Textblock...Whatever-->

</Grid>

Since the Grid has a 0 margin, you can not click it and move it.

Upvotes: 0

AnthonyWJones
AnthonyWJones

Reputation: 189485

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.

Upvotes: 1

Related Questions