Windows 10 Universal Windows Platform – Custom Slider

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="CircleSlider" TargetType="Slider">
		<Setter Property="Background" Value="LightSalmon"/>
		<Setter Property="BorderBrush" Value="Salmon"/>
		<Setter Property="BorderThickness" Value="2"/>
		<Setter Property="Foreground" Value="Gold"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="Slider">
					<Grid Margin="{TemplateBinding Padding}">
						<Grid.Resources>
							<Style x:Key="SliderThumbStyle" TargetType="Thumb">
								<Setter Property="BorderThickness" Value="2"/>
								<Setter Property="BorderBrush" Value="Goldenrod"/>
								<Setter Property="Foreground" Value="Gold"/>
								<Setter Property="Template">
									<Setter.Value>
										<ControlTemplate TargetType="Thumb">
											<Ellipse StrokeThickness="2" Stroke="{TemplateBinding BorderBrush}" Fill="{TemplateBinding Foreground}"/>
										</ControlTemplate>
									</Setter.Value>
								</Setter>
							</Style>
						</Grid.Resources>
						<Grid.RowDefinitions>
							<RowDefinition Height="Auto"/>
							<RowDefinition Height="*"/>
						</Grid.RowDefinitions>
						<Grid x:Name="SliderContainer" Background="Transparent" Grid.Row="1">
							<Grid x:Name="HorizontalTemplate">
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="Auto"/>
									<ColumnDefinition Width="Auto"/>
									<ColumnDefinition Width="*"/>
								</Grid.ColumnDefinitions>
								<Grid.RowDefinitions>
									<RowDefinition Height="17"/>
									<RowDefinition Height="Auto"/>
									<RowDefinition Height="17"/>
								</Grid.RowDefinitions>
								<Rectangle x:Name="HorizontalTrackRect" Grid.ColumnSpan="3" Fill="{TemplateBinding Background}" Grid.Row="1" Height="10" RadiusX="5" RadiusY="5"/>
								<Rectangle x:Name="HorizontalDecreaseRect" Fill="{TemplateBinding Background}" Grid.Row="1" Height="10" RadiusX="5" RadiusY="5"/>
								<Rectangle x:Name="HorizontalBorder" Grid.ColumnSpan="3" Grid.Row="1" Stroke="{TemplateBinding BorderBrush}"
							StrokeThickness="{TemplateBinding BorderThickness}" Height="10" RadiusX="5" RadiusY="5"/>
								<Thumb x:Name="HorizontalThumb" AutomationProperties.AccessibilityView="Raw" Background="{ThemeResource SliderThumbBackgroundThemeBrush}"
							Grid.Column="1" DataContext="{TemplateBinding Value}" Grid.Row="1" Style="{StaticResource SliderThumbStyle}" Height="25" Width="25"/>
							</Grid>
							<Grid x:Name="VerticalTemplate" Visibility="Collapsed">
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="17"/>
									<ColumnDefinition Width="Auto"/>
									<ColumnDefinition Width="17"/>
								</Grid.ColumnDefinitions>
								<Grid.RowDefinitions>
									<RowDefinition Height="*"/>
									<RowDefinition Height="Auto"/>
									<RowDefinition Height="Auto"/>
								</Grid.RowDefinitions>
								<Rectangle x:Name="VerticalTrackRect" Grid.Column="1" Fill="{TemplateBinding Background}" Grid.RowSpan="3" Width="10" RadiusX="5" RadiusY="5"/>
								<Rectangle x:Name="VerticalDecreaseRect" Grid.Column="1" Fill="{TemplateBinding Background}" Grid.Row="2"/>
								<Rectangle x:Name="VerticalBorder" Grid.RowSpan="3" Grid.Column="1"  Stroke="{TemplateBinding BorderBrush}"
							StrokeThickness="{TemplateBinding BorderThickness}" Width="10" RadiusX="5" RadiusY="5" />
								<Thumb x:Name="VerticalThumb" AutomationProperties.AccessibilityView="Raw" Background="{ThemeResource SliderThumbBackgroundThemeBrush}"
							Grid.Column="1" DataContext="{TemplateBinding Value}" Grid.Row="1" Style="{StaticResource SliderThumbStyle}" Height="25" Width="25"/>
							</Grid>
						</Grid>
					</Grid>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
</Application.Resources>

It should then appear as such:

10-app-xaml-customslider

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:

<Slider Margin="50" VerticalAlignment="Center" HorizontalAlignment="Stretch" Style="{StaticResource CircleSlider}"/>

It should appear as such:

10-xaml-customslider

Step 10

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

10-simulator

Step 11

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

10-simulator-run-customslider

Step 12

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

10-stop

Step 13

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 14

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

10-emulator-run-customslider

Step 15

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

10-stop

Creative Commons License

Advertisements

3 thoughts on “Windows 10 Universal Windows Platform – Custom Slider

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