Skip to main content

Microsoft Silverlight

Answered Question How to drag a window in Silverlight2?RSS Feed

(0)

tanusree
tanusree

Member

Member

29 points

77 Posts

How to drag a window in Silverlight2?

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
Nat Siva

Member

Member

254 points

42 Posts

Re: How to drag a window in Silverlight2?

In the MouseDown event handler, check the current position is falls between the TitleBar's height. If yes then capture the mouse.

------------------------------------------------
Don't Forgot to click Mark as Answer if this post answers your question
Go Green, Save Tree
Thanks
Nat

tanusree
tanusree

Member

Member

29 points

77 Posts

Re: How to drag a window in Silverlight2?

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.

 

Thanks in advance,

Tanusree

 

Nat Siva
Nat Siva

Member

Member

254 points

42 Posts

Answered Question

Re: How to drag a window in Silverlight2?

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();
        }  
 
    

------------------------------------------------
Don't Forgot to click Mark as Answer if this post answers your question
Go Green, Save Tree
Thanks
Nat
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities