Example of slider in WPF

Introduction

This article demonstrates how to use the value of slider with another control and update its value in WPF.

Here I have used the value of slider in the textblock to show the updated value of slider when it getting sliding. By the text box I am updating the sliding value without using c# code.

to do the above task, I have use the Element Binding feature of WPF. See the bellow code fore more clarification

XAML Code

<Window x:Class="Example02.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Example 01" Height="300" Width="300">
<
Grid>
<
Grid.RowDefinitions >
<
RowDefinition Height="60px" />
<
RowDefinition Height="40px" />
<
RowDefinition Height="40px" />
<
RowDefinition Height="*" />
</
Grid.RowDefinitions>
<
ComboBox Name="FontNameList" ItemsSource="{Binding Source={x:Static Fonts.SystemFontFamilies}}" Height="22" SelectedIndex="22" Grid.Row="0"/>
<
Slider Name="fontSizeSlider" Minimum="5" Maximum="100" Value="10" Grid.Row="1" />
<
TextBox Name="SizeTextBox" Text="{Binding ElementName=fontSizeSlider, Path=Value}" Grid.Row="2"/>
<
TextBlock Text="Example 01" FontFamily="{Binding ElementName=FontNameList, Path=Text}" FontSize="{Binding ElementName=SizeTextBox, Path=Text}" Grid.Row="3"/>
</
Grid>
</
Window>

Summery

Here we did discussion about use of slider control, if any query please feel free to comment

Ebook Download
View all
Learn
View all