Skip to main content
Home Forums Silverlight Programming Programming with JavaScript How to drag a window in Silverlight2?
3 replies. Latest Post by Nat Siva on June 3, 2009.
(0)
tanusree
Member
29 points
77 Posts
05-29-2009 6:50 AM |
I want to drag a window on click of it's titlebar, not on click of anyother control within this window.
I have used code from this link http://silverlight.net/forums/p/12467/41324.aspx. But here I can click on any control within this window to drag the entire window.
Can anyone help me to solve this problem.
Thanks in advance,
Tanusree
Nat Siva
254 points
42 Posts
05-29-2009 9:41 AM |
In the MouseDown event handler, check the current position is falls between the TitleBar's height. If yes then capture the mouse.
06-01-2009 2:43 AM |
Thank u for ur reply.
Here I have used Rectangle as my Title bar.
public DragDropPanel() : base() { this.MouseLeftButtonDown += new MouseButtonEventHandler(DragDropPanel_MouseLeftButtonDown); this.MouseLeftButtonUp += new MouseButtonEventHandler(DragDropPanel_MouseLeftButtonUp); this.MouseMove += new MouseEventHandler(DragDropPanel_MouseMove); this.Cursor = Cursors.Hand; }
void DragDropPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { System.Windows.FrameworkElement c = sender as System.Windows.FrameworkElement; dragOn = true; beginP = e.GetPosition(null); c.Opacity *= 0.5; c.CaptureMouse(); }
Can u plz tell me in the above how to capture rectangle height.
06-03-2009 8:51 AM |
Hi,
The following logic may helps
void DragDropPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { System.Windows.FrameworkElement c = sender as System.Windows.FrameworkElement; dragOn = true; beginP = e.GetPosition(this); c.Opacity *= 0.5; Rectangle rect = c.FindName("Your Rectangle Name") as Rectangle; if (beginP.Y <= rect.ActualHeight ) c.CaptureMouse(); }