Get User Input from a Slider


   
  
<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF" Height="200" Width="300">
    <StackPanel>
        <TextBlock Margin="5" Text="0" FontSize="20" 
                   HorizontalAlignment="Center" Name="txtSliderValue" />
        <Slider LargeChange="10" Margin="5" Maximum="1000" Minimum="0" 
                Name="slider1" TickPlacement="TopLeft" 
                Ticks="100, 200, 400, 800" Value="0"
                ValueChanged="slider_ValueChanged" />
        <Button Name="btnGetSliderValue1" Width="100" 
                Click="GetSliderValue_Click">Get Slider 1 Value</Button>
        <Slider IsSnapToTickEnabled="True" Margin="5" Maximum="1000" 
                Minimum="0" Name="slider2" TickFrequency="25" 
                TickPlacement="BottomRight" Value="1000" 
                ValueChanged="slider_ValueChanged" />
        <Button Name="btnGetSliderValue2" Width="100" 
                Click="GetSliderValue_Click">Get Slider 2 Value</Button>
    </StackPanel>
</Window>
//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<double> e)
        {
            Slider slider = e.OriginalSource as Slider;

            if (slider != null)
            {
                txtSliderValue.Text = slider.Value.ToString();
            }
        }
    }
}

   
    
     


Set Minimun/Maximum value for Slider


   
     

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF" Height="120" Width="300">

    <StackPanel>
        <ProgressBar  Width="200" Height="100" x:Name="progress" Value="30" HorizontalAlignment="Center" Margin="10"/>
        <Slider Value="{Binding ElementName=progress, Path=Value, Mode=TwoWay}" Minimum="0" Maximum="100"  Margin="10"/>
    </StackPanel>

</Window>

   
    
    
    
    
     


Use Slider to control Path Scaling


   
      
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="XAML PhotoGallery">
  <Page.Resources>
    <ScaleTransform x:Key="transform" ScaleX="3" ScaleY="{Binding Path=ScaleX, RelativeSource={RelativeSource Self}}"/>
    <LinearGradientBrush x:Key="shinyBrush" StartPoint="0,0" EndPoint="0,1">
      <GradientStop Offset="0" Color="Gray"/>
      <GradientStop Offset="0.3" Color="#FF222222"/>
      <GradientStop Offset="0.3" Color="Black"/>
      <GradientStop Offset="0.9" Color="Black"/>
      <GradientStop Offset="0.9" Color="#FF222222"/>
      <GradientStop Offset="1" Color="Gray"/>
    </LinearGradientBrush>
  </Page.Resources>
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="50"/>
      <RowDefinition/>
      <RowDefinition Height="55"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="70"/>
      <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Rectangle Grid.ColumnSpan="3" Fill="{StaticResource shinyBrush}"/>
    <Rectangle Grid.Row="2" Grid.ColumnSpan="3" Fill="{StaticResource shinyBrush}"/>
    <Grid Grid.Row="1" Background="White">
      <Slider Margin="20" Orientation="Vertical" Value="{Binding Path=ScaleX, Source={StaticResource transform}, Mode=TwoWay}" Minimum="1" Maximum="10" Height="100"/>
    </Grid>
    <ListBox x:Name="pictureBox" Background="AliceBlue" Grid.Row="1" Grid.Column="1" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
      <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
          <WrapPanel/>
        </ItemsPanelTemplate>
      </ListBox.ItemsPanel>

  <Image Source="c:image.jpg" Margin="3,8" Height="35" LayoutTransform="{StaticResource transform}"/>
    </ListBox>
  </Grid>
</Page>

   
    
    
    
    
    
     


Add a slider control and a border control to the content of the StackPanel, and add a canvas to the border control.


   
      

<Window x:Class="ScaleInCustomSystem"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Scale In Custom System" Height="310" Width="260">
  <StackPanel Height="280" Width="250">
    <Border BorderBrush="Black" BorderThickness="1" Height="200"
      Width="200" Margin="20">
      <Canvas Height="200" Width="200">
        <Canvas.RenderTransform>
          <TransformGroup>
            <ScaleTransform ScaleY="-1" />
            <TranslateTransform Y="200" />
          </TransformGroup>
        </Canvas.RenderTransform>

      </Canvas>
    </Border>
    <Slider Name="slider" Minimum="0" Maximum="3" Value="1"
      TickPlacement="BottomRight" TickFrequency="0.2"
      IsSnapToTickEnabled="True" />
  </StackPanel>
</Window>

   
    
    
    
    
    
     


Binding ProgressBar with Slider


   
     

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF" Height="120" Width="300">

    <StackPanel>
        <ProgressBar Width="200" Height="100" x:Name="progress" Value="30" HorizontalAlignment="Center" Margin="10"/>
        <Slider Value="{Binding ElementName=progress, Path=Value, Mode=TwoWay}" Minimum="0" Maximum="100"  Margin="10"/>
    </StackPanel>

</Window>

   
    
    
    
    
     


Two way data binding between Slider and ProgressBar


   
     

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF" Height="120" Width="300">

    <StackPanel>
        <ProgressBar  Width="200" Height="100" x:Name="progress" Value="30" HorizontalAlignment="Center" Margin="10"/>
        <Slider Value="{Binding ElementName=progress, Path=Value, Mode=TwoWay}" Minimum="0" Maximum="100"  Margin="10"/>
    </StackPanel>

</Window>

   
    
    
    
    
     


Use Slider to control the Bevel


   
    

<Window x:Class="BitmapEffects.Window4"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Bitmap Effects" Height="538" Width="600">
    <StackPanel>
    <Rectangle Height="50" Width="200" Fill="Red" Stroke="Black">
        <Rectangle.BitmapEffect>
            <BevelBitmapEffect 
            BevelWidth="{Binding ElementName=sliderBevel, Path=Value}"
              />
        </Rectangle.BitmapEffect>
    </Rectangle>
    <Slider Minimum="0" Maximum="20" Name="sliderBevel" Value="14"/>
    <TextBox Text="{Binding ElementName=sliderBevel, Path=Value}"/>
     </StackPanel>
</Window>