Wednesday, March 25, 2009

Drag and Drop Simple Game in Silverlight 2.0

Hi All,

If you want to see the capabilities of Drag and Drop in Silverlight 2.0, Here is a simple Game which I tried.

While doing this demonstration I have used ,

1) Microsoft Expression Design 2.0.

2) Microsoft Expression Blend 2.0.

3) Visual Studio 2008.

You can try this now !! (Drag and Drop the Images Bellow and make my Picture)

Steps :

1) First take a Image which you like (I took a Tiger Image) in Microsoft Expression Design as shown bellow.

MEDTiger

2) Then Slice the image as per your requirement.For Slicing you can use bellow tool.

Slice SlicingTiger

3) Then export your slice in .JPG format.

Export

4) Now, As you got slices of the image, Create Silverlight 2.0 Application using Microsoft Expression Blend 2.0.

5) Add all slices in the project which you have just created.

6) Change the Panel of Page.xaml from Grid to Canvas and arrange all Images as shown bellow.

BlendDesign

7) Now you are ready with the design, let’s write the code to make this work. So, open the same project in Microsoft Visual Studio 2008 and open you Page.xaml.cs.

8) First job is to make these images display in random format. I have used a very simple logic here. But if you want you can choose your own logic. To do so, I have written few functions.

ImageSource[] imgs = new ImageSource[12];
private void RandamizeImages()
{
int j = 0;

FillArray();
for (int i = 11; i >=0; i--)
{
ImageSource source = GetImage(i);
SetImage(j, source);
j++;
}
}
private void SetImage(int i,ImageSource image)
{
switch (i)
{
case 0:
Slice1.Source = null;
Slice1.Source = image;
break;
case 1:
Slice2.Source = null;
Slice2.Source = image;
break;
case 2:
Slice3.Source = null;
Slice3.Source = image;
break;
case 3:
Slice4.Source = null;
Slice4.Source = image;
break;
case 4:
Slice5.Source = null;
Slice5.Source = image;
break;
case 5:
Slice6.Source = null;
Slice6.Source = image;
break;
case 6:
Slice7.Source = null;
Slice7.Source = image;
break;
case 7:
Slice8.Source = null;
Slice8.Source = image;
break;
case 8:
Slice9.Source = null;
Slice9.Source = image;
break;
case 9:
Slice10.Source = null;
Slice10.Source = image;
break;
case 10:
Slice11.Source = null;
Slice11.Source = image;
break;
case 11:
Slice12.Source = null;
Slice12.Source = image;
break;
}
}
private void FillArray()
{
imgs[0] = Slice1.Source;
imgs[1] = Slice2.Source;
imgs[2] = Slice3.Source;
imgs[3] = Slice4.Source;
imgs[4] = Slice5.Source;
imgs[5] = Slice6.Source;
imgs[6] = Slice7.Source;
imgs[7] = Slice8.Source;
imgs[8] = Slice9.Source;
imgs[9] = Slice10.Source;
imgs[10] = Slice11.Source;
imgs[11] = Slice12.Source;

}
private ImageSource GetImage(int index)
{
return imgs[index];
}

9) Now call this RandamizeImages() function in the constructor of Page class.

public Page()
{
// Required to initialize variables
InitializeComponent();
RandamizeImages();
}

10) Now, If you try to run this application, you will see all images are getting rendered in Random order.

11) So now, let’s go and write our Drag and Drop logic which is the heart of this application.

12) First you need to declare few variables at class level as bellow.

public partial class Page : UserControl
{

bool IsDragging = false;
Point offset = new Point();
bool Flag=false;
Image img;

13) On every image which you took, you have to write three events as bellow:

a) MouseLeftButtonDown.

b) MouseMove.

c) MouseLeftButtonUp.

private void Slice_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
img = ((Image)sender);
IsDragging = true;
offset = e.GetPosition(img);
img.CaptureMouse();
}

private void Slice_MouseMove(object sender, MouseEventArgs e)
{

if (IsDragging)
{
img.SetValue(Canvas.TopProperty, e.GetPosition(LayoutRoot).Y - offset.Y);
img.SetValue(Canvas.LeftProperty, e.GetPosition(LayoutRoot).X - offset.X);
}

}

private void Slice_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
IsDragging = false;
img.ReleaseMouseCapture();
Flag = false;

}

14) Now the last step is make

bool Flag=false; variable True in the constructor of you Page class and you are done.

15) Run your application and See you game is working :).

Enjoy !!!

Friday, March 20, 2009

Silverlight 3.0 : 3D Page Turn Application

 

Hi All,

I am really excited since I am writing my First Blog. As every one know that Silverlight 3.0 is available in Beta now and Microsoft Expression Blend 3.0 Preview is available with that.

I was looking for 3D implementation and Silverlight 3.0 has the capability of 3D. So, I tried one application which I was trying from last one year that is “Page Turn Application”.

I always enjoy working with Expression Blend although I am not a designer. So here is a demo of Page Turn Application. I hope you will like it.

Silverlight 3.0 Page Turn Application

1) Create Silverlight 3.0 Application by Visual Studio 2008 and Open MainControl.Xaml File. Copy the bellow code in MainControl.Xaml file.

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Class="PageTurnApplication.MainControl"

Width="640" Height="480" mc:Ignorable="d">
<UserControl.Resources>
<Storyboard x:Name="NextPage1Ani">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="Img1" Storyboard.TargetProperty="(UIElement.Projection).
(PlaneProjection.RotationY)"
>
<EasingDoubleKeyFrame KeyTime="00:00:04" Value="180"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="NextPage2Ani">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img1"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">

<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="Img2" Storyboard.TargetProperty="(UIElement.Projection).
(PlaneProjection.RotationY)"
>
<EasingDoubleKeyFrame KeyTime="00:00:04" Value="180"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="NextPage3Ani">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img1"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img2"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="Img3" Storyboard.TargetProperty="(UIElement.Projection).
(PlaneProjection.RotationY)"
>
<EasingDoubleKeyFrame KeyTime="00:00:04" Value="180"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="NextPage4Ani">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img1"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img2"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img3"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="Img4" Storyboard.TargetProperty="(UIElement.Projection).
(PlaneProjection.RotationY)"
>
<EasingDoubleKeyFrame KeyTime="00:00:04" Value="180"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="NextPage5Ani">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img1"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img2"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img3"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img4"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="Img5" Storyboard.TargetProperty="(UIElement.Projection).
(PlaneProjection.RotationY)"
>
<EasingDoubleKeyFrame KeyTime="00:00:04" Value="180"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="NextPage6Ani">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img1"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img2"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img3"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img4"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img5"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="Img6" Storyboard.TargetProperty="(UIElement.Projection).
(PlaneProjection.RotationY)"
>
<EasingDoubleKeyFrame KeyTime="00:00:04" Value="180"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="PagePrevious1Ani">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img5"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img4"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img3"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img2"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img1"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="Img6" Storyboard.TargetProperty="(UIElement.Projection).
(PlaneProjection.RotationY)"
>
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
<EasingDoubleKeyFrame KeyTime="00:00:04" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="PagePrevious2Ani">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="Img5" Storyboard.TargetProperty="(UIElement.Projection).
(PlaneProjection.RotationY)"
>
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
<EasingDoubleKeyFrame KeyTime="00:00:04" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img4"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img3"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img2"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img1"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="PagePrevious3Ani">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="Img4" Storyboard.TargetProperty="(UIElement.Projection).
(PlaneProjection.RotationY)"
>
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
<EasingDoubleKeyFrame KeyTime="00:00:04" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img3"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img2"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img1"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="PreviousPage4Ani">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="Img3" Storyboard.TargetProperty="(UIElement.Projection).
(PlaneProjection.RotationY)"
>
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
<EasingDoubleKeyFrame KeyTime="00:00:04" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img2"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img1"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="PagePrevious5Ani">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="Img2" Storyboard.TargetProperty="(UIElement.Projection).
(PlaneProjection.RotationY)"
>
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
<EasingDoubleKeyFrame KeyTime="00:00:04" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000" Storyboard.TargetName="Img1"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="PagePrevoius6Ani">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="Img1" Storyboard.TargetProperty="(UIElement.Projection).
(PlaneProjection.RotationY)"
>
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
<EasingDoubleKeyFrame KeyTime="00:00:04" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>

<Grid x:Name="LayoutRoot" Background="Black">
<Image x:Name="nxtButton" HorizontalAlignment="Right"
Margin="0,219,203,211" Width="50" Source="Next.png" Stretch="Fill"
MouseLeftButtonDown="nxtButton_MouseLeftButtonDown"/>
<Image x:Name="prevButton" HorizontalAlignment="Left" Margin="50,219,0,211"
Width="50" Source="Previous.png" Stretch="Fill"
MouseLeftButtonDown="prevButton_MouseLeftButtonDown" />
<Image x:Name="Img6" Margin="251,83,189,297" Source="Waterfall.jpg"
Stretch="Fill" Height="100">
<Image.Projection>
<PlaneProjection CenterOfRotationY="10" CenterOfRotationX="0"
RotationY="0"/>
</Image.Projection>
</Image>
<Image x:Name="Img5" Margin="251,83,189,297" Source="leaves.jpg"
Stretch="Fill" Height="100">
<Image.Projection>
<PlaneProjection CenterOfRotationY="10" CenterOfRotationX="0"
RotationY="0"/>
</Image.Projection>
</Image>
<Image x:Name="Img4" Margin="251,83,189,297" Source="Tulip.jpg"
Stretch="Fill" Height="100">
<Image.Projection>
<PlaneProjection CenterOfRotationY="10" CenterOfRotationX="0"
RotationY="0"/>
</Image.Projection>
</Image>
<Image x:Name="Img3" Margin="251,83,189,297" Source="Creek.jpg"
Stretch="Fill" Height="100">
<Image.Projection>
<PlaneProjection CenterOfRotationY="10" CenterOfRotationX="0"
RotationY="0"/>
</Image.Projection>
</Image>
<Image x:Name="Img2" Margin="251,83,189,297" Source="Butterfly.jpg"
Stretch="Fill" Height="100">
<Image.Projection>
<PlaneProjection CenterOfRotationY="10" CenterOfRotationX="0"
RotationY="0"/>
</Image.Projection>
</Image>
<Image x:Name="Img1" Margin="251,83,189,297" Source="Flower.jpg"
Stretch="Fill" Height="100">
<Image.Projection>
<PlaneProjection CenterOfRotationY="10" CenterOfRotationX="0"
RotationY="0"/>
</Image.Projection>
</Image>
<Image Margin="0,-55,264.464,0" Source="Borders.png" Stretch="Fill"
RenderTransformOrigin="0.5,0.5" d:LayoutRounding="Auto" UseLayoutRounding="False"
VerticalAlignment="Top" Height="239" Width="17.072" HorizontalAlignment="Right">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="-90"/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>
<Image Margin="0,82.75,264.464,158.25" Source="Borders.png" Stretch="Fill"
RenderTransformOrigin="0.5,0.5" d:LayoutRounding="Auto" UseLayoutRounding="False"
HorizontalAlignment="Right" Width="17.072">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="-90"/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>
<Image Margin="120.464,-55,0,0" Source="Borders.png" Stretch="Fill"
RenderTransformOrigin="0.5,0.5" d:LayoutRounding="Auto" UseLayoutRounding="False"
VerticalAlignment="Top" Height="239" HorizontalAlignment="Left" Width="17.072">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="-90"/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>
<Image Margin="120.464,82.75,0,158.25" Source="Borders.png" Stretch="Fill"
RenderTransformOrigin="0.5,0.5" d:LayoutRounding="Auto" UseLayoutRounding="False"
HorizontalAlignment="Left" Width="17.072">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="-90"/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>
</Grid>
</UserControl>





2) Now Let’s Start coding MainControl.xaml.cs file as shown bellow-




public partial class MainControl : UserControl
{
public MainControl()
{
// Required to initialize variables
InitializeComponent();
prevButton.Visibility = Visibility.Collapsed;
}
private void resetZIndexNormal()
{

Canvas.SetZIndex(Img6, 11);
Canvas.SetZIndex(Img5, 12);
Canvas.SetZIndex(Img4, 13);
Canvas.SetZIndex(Img3, 14);
Canvas.SetZIndex(Img2, 15);
Canvas.SetZIndex(Img1, 16);

}
private void resetZIndexReverse()
{

Canvas.SetZIndex(Img1, 31);
Canvas.SetZIndex(Img2, 32);
Canvas.SetZIndex(Img3, 33);
Canvas.SetZIndex(Img4, 34);
Canvas.SetZIndex(Img5, 35);
Canvas.SetZIndex(Img6, 36);

}
static int nextCount=1,previousCount=1;
bool reverse = false;
private void nxtButton_MouseLeftButtonDown(object sender,
MouseButtonEventArgs e)
{
if (reverse == false)
{
resetZIndexNormal();
reverse = true;
}

switch (nextCount)
{
case 1:

NextPage1Ani.Stop();
NextPage1Ani.Begin();
nextCount++;
Canvas.SetZIndex(Img1, 21);
break;
case 2:

NextPage2Ani.Stop();
NextPage2Ani.Begin();
nextCount++;
Canvas.SetZIndex(Img2, 22);
break;
case 3:

NextPage3Ani.Stop();
NextPage3Ani.Begin();
nextCount++;
Canvas.SetZIndex(Img3, 23);
break;
case 4:

NextPage4Ani.Stop();
NextPage4Ani.Begin();
nextCount++;
Canvas.SetZIndex(Img4, 24);
break;
case 5:

NextPage5Ani.Stop();
NextPage5Ani.Begin();
nextCount++;
Canvas.SetZIndex(Img5, 25);
break;
case 6:

NextPage6Ani.Stop();
NextPage6Ani.Begin();
nextCount++;
Canvas.SetZIndex(Img6, 26);
nextCount=1;
nxtButton.Visibility = Visibility.Collapsed;
prevButton.Visibility = Visibility.Visible;
reverse = true;
break;

}
}


private void prevButton_MouseLeftButtonDown(object sender,
MouseButtonEventArgs e)
{
if (reverse == true)
{
resetZIndexReverse();
reverse = false;

}
switch (previousCount)
{
case 1:

PagePrevious1Ani.Stop();
PagePrevious1Ani.Begin();
previousCount++;
Canvas.SetZIndex(Img6, 41);
break;
case 2:

PagePrevious2Ani.Stop();
PagePrevious2Ani.Begin();
previousCount++;
Canvas.SetZIndex(Img5, 42);
break;
case 3:

PagePrevious3Ani.Stop();
PagePrevious3Ani.Begin();
previousCount++;
Canvas.SetZIndex(Img4, 43);
break;
case 4:

PreviousPage4Ani.Stop();
PreviousPage4Ani.Begin();
previousCount++;
Canvas.SetZIndex(Img3, 44);
break;
case 5:

PagePrevious5Ani.Stop();
PagePrevious5Ani.Begin();
previousCount++;
Canvas.SetZIndex(Img2, 45);
break;
case 6:

PagePrevoius6Ani.Stop();
PagePrevoius6Ani.Begin();
previousCount++;
Canvas.SetZIndex(Img1, 46);
previousCount=1;
nxtButton.Visibility = Visibility.Visible;
prevButton.Visibility = Visibility.Collapsed;
reverse = false;

break;
}
}
}





Enjoy !!!