index > WPF Designer ("Cider") > Moving a control on a Canvas at run time

Moving a control on a Canvas at run time


Hi,

I'm trying to produce a simple designer in Xaml, for a test app I've produced the following Xaml:

<Window x:Class="xamlWindowsApp.frmDesigner" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="xamlWindowsApp" Height="450" Width="582" xmlns:my="clr-namespace:System;assembly=mscorlib">

<DockPanel Margin="1,1,2,2" MinHeight="50" MinWidth="50" Name="dockPanel1" LastChildFill ="True">

<Canvas MouseLeftButtonUp ="OnLeftButtonUp">

<Label MouseLeftButtonDown ="OnLeftButtonDown" MouseLeftButtonUp ="OnLeftButtonUp" MouseMove ="OnMouseMove" HorizontalAlignment="Right" Name="label1" Width="60" BorderBrush="#FFC0C0C0" BorderThickness="3,3,3,3" Height="30" VerticalAlignment="Bottom" Canvas.Left="40" Canvas.Top="10">Movable</Label>

</Canvas>

</DockPanel>

</Window>

I have two question:

1. How do I get the location of the mouse on the canvas?

2. How do I change the Labels canvas properties so that I can get it to track the mouse within the canvas.

Thanks in advance for any help

AndyH

LokiDBA

I have found how to get the mouse location on the canvas using:

System.Windows.Input.Mouse.GetPosition(this)

Does anyone one know if there is a better or Best Practice way of doing this.

Thanks

Andy

LokiDBA

Hi Andy,

This forum is for the WPF Designer for Visual Studio. For questions about the WPF runtime behaviors & usage, please post to the WPF Forum (http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=119&SiteID=1). There are many smart eyeballs there, I'm certain you'll find some suggestions on run-time mouse capture & layout.

thanks

chad




chad royal | project cider | microsoft | as is, no warranties, no rights
chadr - msft

Thanks, will do.

Found a possible answer, you can use static methods

Canvas.SetTop( object, value)

Canvas.SetRight(object, value)

Canvas.SetLeft(object, value)

Canvas.SetBottom(object, value)

But I'll definatly check the other forum out for the best practice.

Thanks again.

Andy

LokiDBA

Depending on what you are trying to accomplish, you may be interested in the InkCanvas class which provides an edit mode that allows the end user to select and move its child elements.

http://www.windojitsu.com/blog/tictactoefx.html

http://windowssdk.msdn.microsoft.com/en-us/library/system.windows.controls.inkcanvas.aspx




Jim Nakashima, Microsoft. (This post is provided "as-is")
Jim Nakashima - MSFT
reply 5

You can use google to search for other answers

 

More Articles

• Cannot download Expression Graphic Designer
• how to put glass borders in a application?
• I hate June CTP
• WinFX Data Binding using VS 2005
• December CTP Installation trouble
• When Cider update beyond June CTP
• LOCAL AREA CONNECTION : DESKTOP PC WITH LAPTOPS
• Install Problem - VS 2005 Step
• 3D samples in Windows SDK not modified for feb CTP
• Limitations of December CTP (Cider) release?
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

• User controls
• Can't go directly to XAML edit
• MouseEvents (WindowStyle"None"
• February CTP Cider
• cider install
• Working with a Canvas in Cider Designer
• Cider Glossary
• Databinding, Templates
• XAML without cider?
• Install Problem - VS 2005 Step
• Announcing the Cider September CTP! (for
• No Designer View in VS
• LOCAL AREA CONNECTION : DESKTOP PC WITH
• More training videos/ tutorials for the
• Unhandled Exception when moving mouse of

Hot Articles

• Custom Control Support in Cider
• vista dev/cider labs
• How to delete a control on a form?
• Auto-refactor doesn't work in the Cider
• When will Cider be available for C++ dev
• Button Events
• Design view goes "Whoops" on m
• RC1 support?
• Mismatched versions of PresentationCore.
• design time features in feb. ctp
• problem orcas converts old sln and vcpro
• Cider type initializer error
• I hate June CTP
• Cider Glossary
• February CTP Cider

Recommend Articles

• Designer not showing up
• XAML images
• Can't read Y coordinate value when resiz
• Cider and other tools
• Cider Release Strategy
• Toolbar with Image control in XAML Page
• Announcing the Cider September CTP! (for
• Need help to make a strategic decision.
• When will Cider be available for C++ dev
• Localization Support
• The project type is not supported by thi
• Adding controls to container
• Fidalgo vs Orcas
• Design Surface in CIDER
• Components in CIDER