locked
How can we stop drag and drop of a Child Window in Silverlight RRS feed

  • Question

  • Hi,

    Please tell how can we stop drag and drop of a Child Window in Silverlight. Please tell me code for that.

    It is very urgent.

    Thanks in Advance

    Rahul

    Friday, November 11, 2011 4:44 AM

Answers

All replies

  • can you explain better?
    Friday, November 11, 2011 5:25 AM
  • I am using a child window which I am calling in my MainPage.xaml on a click of a Hyperlink.

    I want the user should not drag and drop the that child window.

    Thanks

    Rahul

    Friday, November 11, 2011 5:54 AM
  • There is no property for that. But you can restrict the dragging of ChildWindow by restyling it. Look at the ChildWindow style - http://msdn.microsoft.com/en-us/library/dd833070(v=vs.95).aspx

    e.g. you can set the height of element corresponding to chrome to 0. Or you can set chrome element's IsHitTestVisible property to false.

    Friday, November 11, 2011 6:12 AM
  • If I use the above code, the child window doesnt drag but the events of child window doesnt work.

    Is there anyother way, you can help me out.

    Thanks in advance

    Rahul

    Friday, November 11, 2011 12:26 PM
  • Hi Rahul,

    In ChildWindow, all movement event is attached to a Border named as Chrome inside ChildWindow template, so to make ChildWindow unmovable, you can edit the built-in ChildWindow and remove the x:Name="Chrome" attribute.

    AnthonyWJones explain the detailed process at below link

    http://stackoverflow.com/questions/2674353/silverlight-preventing-childwindow-movement

     

    Best Regards,


     

    Sunday, November 13, 2011 10:24 PM
  • Removing template parts is not a good idea. It may work for this case but generally it shouldn't be done.  I have experienced a couple of problems when I did this (I don't remember actual controls which had these problems):

    1. Crash/abnormal behavior - Maybe because the control implementation depends on this part.
    2. Failure in automation through CodedUI tests - Maybe the testcontrol implementation is also dependent on named parts of corresponding Silverlight control

    Thats why I find it better to set the part's height to zero/change its visibility/change its hittestvisible property.

    Sunday, November 13, 2011 11:44 PM
  • Thanks for your answer, NKC1.  I needed to do this in code because I wanted to disable dragging in certain circumstances and re-enable it in others, and your solution worked perfectly for me.  The code, if anyone needs it:

                FrameworkElement root = (FrameworkElement)VisualTreeHelper.GetChild(this, 0);
    FrameworkElement chrome = (FrameworkElement)root.FindName("Chrome");
    if (chrome != null) {
    chrome.IsHitTestVisible = false;
    }

    And of course to re-enable dragging, just set it back to true.

    
    

    Sunday, April 15, 2012 8:28 PM