Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Phone

Programming Windows Phone 7 : The Intricacies of Layout - The Canvas and Touch

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
3/8/2011 10:37:05 PM

Here’s a simple program called TouchCanvas. A Canvas hosts three Ellipse elements colored red, green, and blue:

Example 1. Silverlight Project: TouchCanvas File: MainPage.xaml (excerpt)
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Canvas Name="canvas">
<Ellipse Canvas.Left="50"
Canvas.Top="50"
Width="100"
Height="100"
Fill="Red" />

<Ellipse Canvas.Left="150"
Canvas.Top="150"
Width="100"
Height="100"
Fill="Green" />

<Ellipse Canvas.Left="250"
Canvas.Top="250"
Width="100"
Height="100"
Fill="Blue" />
</Canvas>
</Grid>

The code file overrides the OnManipulationStarted and OnManipulationDelta methods in MainPage. Setting the ManipulationContainer property to the Canvas in the first override isn’t strictly required.

Example 2. Silverlight Project: TouchCanvas File: MainPage.xaml.cs (excerpt)
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
}
protected override void OnManipulationStarted(ManipulationStartedEventArgs args)
{
args.ManipulationContainer = canvas;
base.OnManipulationStarted(args);
}

protected override void OnManipulationDelta(ManipulationDeltaEventArgs args)
{
UIElement element = args.OriginalSource as UIElement;
Point translation = args.DeltaManipulation.Translation;
Canvas.SetLeft(element, Canvas.GetLeft(element) + translation.X);
Canvas.SetTop(element, Canvas.GetTop(element) + translation.Y);

args.Handled = true;
base.OnManipulationDelta(args);
}
}


The OnManipulationDelta override moves one of the ellipses by obtaining its Left and Top settings, adding the delta translation factors, and then setting them back, all in fairly short and clean statements.

Other -----------------
- Programming Windows Phone 7 : The Intricacies of Layout - The Retro Canvas
- Programming Windows Phone 7 : The Intricacies of Layout - A Custom Vertical StackPanel
- Programming Windows Phone 7 : The Intricacies of Layout - A Single-Cell Grid Clone
- Programming Windows Phone 7 : The Intricacies of Layout - The Mechanism of Layout
- Programming Windows Phone 7 : The Intricacies of Layout - Two ScrollViewer Applications
- Programming Windows Phone 7 : The Intricacies of Layout - Visibility and Layout
- Programming Windows Phone 7 : The Intricacies of Layout - Nested Panels
- Programming Windows Phone 7 : The Intricacies of Layout - Text Concatenation with StackPanel
- Programming Windows Phone 7 : The Intricacies of Layout - The StackPanel Stack
- Programming Windows Phone 7 : The Intricacies of Layout - The Single-Cell Grid
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server