xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF" Height="200" Width="300">
HorizontalAlignment="Center" Name="txtSliderValue" />
Name="slider1" TickPlacement="TopLeft"
Ticks="100, 200, 400, 800" Value="0"
ValueChanged="slider_ValueChanged" />
Click="GetSliderValue_Click">Get Slider 1 Value
Minimum="0" Name="slider2" TickFrequency="25"
TickPlacement="BottomRight" Value="1000"
ValueChanged="slider_ValueChanged" />
Click="GetSliderValue_Click">Get Slider 2 Value
//File:Window.xaml.cs
using System.Windows;
using System.Windows.Controls;
namespace WpfApplication1
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void GetSliderValue_Click(object sender, RoutedEventArgs e)
{
Button button = e.OriginalSource as Button;
string message = "Unknown slider.";
if (button == btnGetSliderValue1)
{
message = "Slider1 value = " + slider1.Value;
}
else if (button == btnGetSliderValue2)
{
message = "Slider2 value = " + slider2.Value;
}
MessageBox.Show(message, Title);
}
private void slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
{
Slider slider = e.OriginalSource as Slider;
if (slider != null)
{
txtSliderValue.Text = slider.Value.ToString();
}
}
}
}