Windows 10 Universal Windows Platform – Custom Button

Step 1

Download Visual Studio Community 2015 and install it onto your computer, if it’s already downloaded and installed select Launch to start Visual Studio Community 2015 or if it has already been downloaded and installed then start the application you may also need to Enable your device for development.

10-home

Step 2

Once Visual Studio Community 2015 has started select File, then New, then Project… from the Menu.

10-file-new-project

Step 3

From the New Project window select Visual C# from Installed, Templates then select Blank App (Windows Universal) from the list, then type in a Name and select a Location to save to before selecting Ok to create the Project.

10-new-project

Step 4

Once the Project is created from the Solution Explorer select App.xaml

10-app

Step 5

Select from the Menu, View then Designer

10-designer

Step 6

Once in the Design View for App.xaml above </Application> the following should be entered:

<Application.Resources>
	<Style x:Key="CircleButton" TargetType="Button">
		<Setter Property="Background">
			<Setter.Value>
				<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
					<GradientStop Offset="0" Color="Gold"/>
					<GradientStop Offset="1" Color="Goldenrod"/>
				</LinearGradientBrush>
			</Setter.Value>
		</Setter>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="Button">
					<Grid>
						<VisualStateManager.VisualStateGroups>
							<VisualStateGroup x:Name="CommonStates">
								<VisualState x:Name="Disabled"/>
								<VisualState x:Name="Normal"/>
								<VisualState x:Name="MouseOver"/>
								<VisualState x:Name="Pressed">
									<Storyboard>
										<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Inner" Storyboard.TargetProperty="(ScaleTransform.ScaleY)">
											<DiscreteObjectKeyFrame KeyTime="0:0:0.0" Value="1"/>
										</ObjectAnimationUsingKeyFrames>
										<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Outer" Storyboard.TargetProperty="(ScaleTransform.ScaleY)">
											<DiscreteObjectKeyFrame KeyTime="0:0:0.0" Value="-1"/>
										</ObjectAnimationUsingKeyFrames>
									</Storyboard>
								</VisualState>
							</VisualStateGroup>
							<VisualStateGroup x:Name="FocusStates">
								<VisualState x:Name="Focused"/>
								<VisualState x:Name="Unfocused"/>
							</VisualStateGroup>
						</VisualStateManager.VisualStateGroups>
						<Ellipse Margin="4" Fill="{TemplateBinding Background}" RenderTransformOrigin="0.5,0.5">
							<Ellipse.RenderTransform>
								<ScaleTransform ScaleY="1" x:Name="Outer"/>
							</Ellipse.RenderTransform>
						</Ellipse>
						<Ellipse Margin="20" Fill="{TemplateBinding Background}" RenderTransformOrigin="0.5,0.5">
							<Ellipse.RenderTransform>
								<ScaleTransform ScaleY="-1" x:Name="Inner"/>
							</Ellipse.RenderTransform>
						</Ellipse>
						<ContentPresenter x:Name="content" HorizontalAlignment="Center" VerticalAlignment="Center"/>
					</Grid>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
</Application.Resources>

It should then appear as such:

10-app-xaml-custombutton

Step 7

From the Solution Explorer select MainPage.xaml

10-mainpage

Step 8

Select from the Menu, View then Designer

10-designer

Step 9

The Design View will be displayed along with the XAML View and in this below <Grid Background=”{ThemeResource ApplicationPageBackgroundThemeBrush}”> enter the following XAML:

<Button Height="200" Width="200" Content="Tap Here" HorizontalAlignment="Center" Style="{StaticResource CircleButton}" Click="Button_Click"/>

It should appear as such:

10-xaml-custombutton

Step 10

Select from the Menu, View then Code

10-code

Step 11

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

private async void Button_Click(object sender, RoutedEventArgs e)
{
	await new Windows.UI.Popups.MessageDialog("Hello World").ShowAsync();
}

It should then appear as such:

10-code-custombutton

Step 12

That completes the Windows Universal Application so Save the Project then select the Debug and Simulator option to run the Application

10-simulator

Step 13

Once the Simulator has started the Application should then appear with the Custom Button displayed

10-simulator-run-custombutton

Step 14

To Exit the application select Stop Debugging in Visual Studio Community 2015

10-stop

Step 15

Another option is to run as a Windows Phone application, select Debug and select Emulator 10.0.1.0 WVGA 4 inch 512MB option to run the Application

10-emulator

Step 16

Once the Emulator has started the Application should then appear with the Custom Button displayed

10-emulator-run-custombutton

Step 17

To Exit the application select Stop Debugging in Visual Studio Community 2015

10-stop

Creative Commons License

Advertisements

One thought on “Windows 10 Universal Windows Platform – Custom Button

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s