Xamarin September – Image Rotate

Standard

Step 1

If not already, follow Setup and Start on how to Install and get Started with Visual Studio 2017 or in Windows 10 choose Start, and then from the Start Menu locate and select Visual Studio 2017.

xamarin-vs2017-home

Step 2

Once Visual Studio Community 2017 has started, from the Menu choose File, then New then Project…

xamarin-vs2017-file-new-project

Step 3

From New Project choose Visual C# from Installed, Templates then choose Cross Platform App (Xamarin) and then type in a Name and select a Location and then select Ok to create the Project

xamarin-vs2017-new-project

Step 4

Then in New Cross Platform App you need to select the Blank App Template then from UI Technology select Xamarin.Forms and in Code Sharing Strategy select Shared Project and then select Ok to continue

xamarin-vs2017-cross-platform

Step 5

The Xamarin Mac Agent will be displayed allowing connection to an Apple Mac but this can be dismissed with Close if running solely on Windows 10

xamarin-vs2017-mac-agent

Step 6

Then in New Universal Windows Project you need to select the Target Version to be Windows 10 Creators Update (10.0; Build 15063) and the Minimum Version to Windows 10 Creators Update (10.0; Build 15063) and then select Ok

xamarin-vs2017-target

Step 7

In the Solution Explorer select MainPage.xaml from the Shared Project

xamarin-vs2017-mainpage-xaml

Step 8

From the Menu choose View and then Open

xamarin-vs2017-view-open

Step 9

The XAML View will be displayed, and in this remove the Label then between the ContentPage and /ContentPage elements, enter the following XAML:

<Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
	<Grid.RowDefinitions>
		<RowDefinition Height="Auto"/>
		<RowDefinition Height="*"/>
		<RowDefinition Height="Auto"/>
	</Grid.RowDefinitions>
	<Entry Grid.Row="0" x:Name="Value" Margin="10" Completed="Value_Completed"/>
	<Image Grid.Row="1" x:Name="Display" Margin="10" Aspect="AspectFit" 
		HorizontalOptions="Center" VerticalOptions="Center"/>
	<StackLayout Grid.Row="2">
		<Label Text="X" Margin="10"/>
		<Slider x:Name="RotateX" Minimum="0" Maximum="360" ValueChanged="RotateX_ValueChanged" Margin="10"/>
		<Label Text="Y" Margin="10"/>
		<Slider x:Name="RotateY" Minimum="0" Maximum="360" ValueChanged="RotateY_ValueChanged" Margin="10"/>
		<Label Text="Z" Margin="10"/>
		<Slider x:Name="RotateZ" Minimum="0" Maximum="360" ValueChanged="RotateZ_ValueChanged" Margin="10"/>
	</StackLayout>
</Grid>

It should appear as such:

xamarin-xaml-data-input

Step 10

In the Solution Explorer select the Expand arrow next to MainPage.xaml to open MainPage.cs, then select this from the Shared Project

xamarin-vs2017-mainpage-cs

Step 14

From the Menu choose View and then Open

xamarin-vs2017-view-open

Step 15

Once in the Code View, below the public MainPage() { … } the following Code should be entered:

public void Value_Completed(object sender, EventArgs e)
{
	Display.Source = ImageSource.FromUri(new Uri(Value.Text));
}

public void RotateX_ValueChanged(object sender, ValueChangedEventArgs e)
{
	Display.RotationX = RotateX.Value;
}

public void RotateY_ValueChanged(object sender, ValueChangedEventArgs e)
{
	Display.RotationY = RotateY.Value;
}

public void RotateZ_ValueChanged(object sender, ValueChangedEventArgs e)
{
	Display.Rotation = RotateZ.Value;
}

It should then appear as such:

xamarin-code-image-rotate

Step 16

That completes the application, so from the Menu choose Build and then Build Solution

xamarin-vs2017-build-solution

Step 17

Then from the Menu choose Debug then Start Debugging to run the Application in the Android Emulator

xamarin-vs2017-debug-start

Step 18

Once started the Application should then appear in the Android Emulator

xamarin-android-run-image-rotate

Step 19

After the Application has started running you can then type in the URL of any image e.g. https://dummyimage.com/300×200/000000/ffffff&text=Hello+World then press or tap Enter or Submit to load this, then use the X, Y or Z sliders to rotate the image

xamarin-android-ran-image-rotate

Step 20

To Exit the Application select Stop in Visual Studio

xamarin-vs2017-stop

Step 21

Another option is to run as a Universal Windows Application. From Solution Explorer select the Project ending with .UWP (Universal Windows), then from the Menu choose Project then Set as StartUp Project

xamarin-vs2017-project-startup

Step 22

Then again from the Menu choose Build and then select the Deploy option ending with .UWP

xamarin-vs2017-uwp-deploy

Step 23

Then once again from the Menu choose Debug then Start Debugging to run the Application in Windows 10

xamarin-vs2017-debug-start

Step 24

Once started the Application should then appear

xamarin-uwp-run-image-rotate

Step 25

After the Application has started running you can then type in the URL of any image e.g. https://dummyimage.com/300×200/000000/ffffff&text=Hello+World then press or tap Enter or Submit to load this, then use the X, Y or Z sliders to rotate the image

xamarin-uwp-ran-image-rotate

Step 26

To Exit the Application select Stop in Visual Studio

xamarin-vs2017-stop

Step 27

Also if you have Mac with the Xamarin tools installed and have enabled and connected to the Xamarin Mac Agent. From Solution Explorer select the Project ending with .iOS, then from the Menu choose Project then Set as StartUp Project

xamarin-vs2017-project-startup

Step 28

Then once again from the Menu choose Debug then Start Debugging to run the Application for iOS

xamarin-vs2017-debug-start

Step 29

Once started the Application should then appear

Screenshots provided by Julia Boichentsova

Step 30

After the Application has started running you can then type in the URL of any image e.g. https://dummyimage.com/300×200/000000/ffffff&text=Hello+World then press or tap Enter or Submit to load this, then use the X, Y or Z sliders to rotate the image

Screenshots provided by Julia Boichentsova

Step 31

To Exit the Application select Stop in Visual Studio

xamarin-vs2017-stop

Thanks for Julia Boichentsova for helping with iOS screenshots

Creative Commons License

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s