ARTICLE

WPF Slider

Posted by Dinesh Beniwal Articles | WPF using VB.NET December 02, 2008
This article shows how create and use a slider control using WPF and XAML.
Download Files:
 
Reader Level:

 

The Slider XAML element represents a slider control in XAML. A slider control's default minimum and maximum values are 0 and 10.

The Maximim and Minimum attributes are used to set minimum and maximum values of a slider control.

<Slider Height="23" HorizontalAlignment="Left" Margin="26,34,0,0"
Name="slider1" VerticalAlignment="Top" Width="250"
Minimum="0" Maximum="100" />

Now, let's create a sample where slider action will change the value of a ProgressBar control.



In the below code, the key is setting the Value property of ProgressBar to Bind with the value of the Slider using ElementName.

Value="{Binding Path=Value, ElementName=Slider

Here is the complete sample:

<Window
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      x:Class="SliderDB.Window1"
      x:Name="Window"
      Title="Window1"
      Width="640" Height="480">

       <Grid x:Name="LayoutRoot">
            <Slider RenderTransformOrigin="0.501,0.622" Margin="81,161.66,66,0"
            x:Name="Slider" Style="{DynamicResource SimpleSlider}"
            VerticalAlignment="Top" Height="22" Maximum="100" Minimum="0" Value="0"         >
                  <Slider.RenderTransform>
                        <TransformGroup>
                              <ScaleTransform ScaleX="-1" ScaleY="-1"/>
                              <SkewTransform AngleX="0" AngleY="0"/>
                              <RotateTransform Angle="179.863"/>
                              <TranslateTransform X="-0.954" Y="-9.028"/>
                        </TransformGroup>
                  </Slider.RenderTransform>
                  <Slider.Background>
                        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                              <GradientStop Color="#FFFFFFFF" Offset="0"/>
                              <GradientStop Color="#FFF5A544" Offset="1"/>
                        </LinearGradientBrush>
                  </Slider.Background>
            </Slider>
            <ProgressBar Margin="80,119,63,0" Style="{DynamicResource SimpleProgressBar}"
             VerticalAlignment="Top" Height="20"
             Value="{Binding Path=Value, ElementName=Slider, Mode=Default}">
                  <ProgressBar.Background>
                        <LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
                              <GradientStop Color="#FFBABABA" Offset="0"/>
                              <GradientStop Color="#FFC7C7C7" Offset="0.5"/>
                              <GradientStop Color="#FF5D9C1D" Offset="0.75"/>
                        </LinearGradientBrush>
                  </ProgressBar.Background>
            </ProgressBar>
                     </Grid>
</
Window>

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor