Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Drag and Drop
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Miscellaneous
Thread ID:
01488442
Message ID:
01488488
Views:
34
Hi Viv. Many thanks for samples.
I'll experiment with these.
regards,
Gerard


>
<Canvas x:Name="Holder" Grid.Row="2" Width="200" Height="200">
>                <Rectangle x:Name="Rect" Width="20" Height="20" Canvas.Left="10" Canvas.Top="10" Fill="Red" 
>                           MouseLeftButtonDown="Rectangle_MouseLeftButtonDown"
>                           MouseMove="Rectangle_MouseMove"
>                           MouseLeftButtonUp="Rect_MouseLeftButtonUp"
>                           ></Rectangle>
>            </Canvas>
Point p;
>        bool dragging;
>
>        private void Rectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
>        {
>            dragging = true;
>             p = e.GetPosition(Holder);
>        }
>
>        private void Rectangle_MouseMove(object sender, MouseEventArgs e)
>        {
>            if (dragging)
>            {
>                Point p2 = e.GetPosition(Holder);
>                Rect.SetValue(Canvas.TopProperty, (double)Rect.GetValue(Canvas.TopProperty) + ( p2.Y - p.Y));
>                Rect.SetValue(Canvas.LeftProperty, (double)Rect.GetValue(Canvas.LeftProperty) + (p2.X - p.X));
>                p = p2;
>            }
>        }
>
>        private void Rect_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
>        {
>            dragging = false;
>        }
Crude (if you drag too fast the mouse up can occur outside the Rectangle etc) but should get you started.....
>
>
>>I have a silverlight control (e.g. a Rectangle or ellipse) on a form.
>>I just want to be able to move it around the form at run time but dont see an automatic way of doing this... i.e. there is not a 'Movable' or Draggable' property.
>>Regards,
>>Gerard
>>
>>
>>
>>
>>>>Is there a way to enable a silverlight control to be 'Movable' i.e. drag and drop it to a diferent position on the screen
>>>
>>>I assume you mean a SilverLight control within a Silverlight container rather than a Silverlight object within a web page ?
>>>If so then yes. Especially if you can use a Canvas control as the container since it allows for very simple exact positioning....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform