Reputation: 395
Is there any way to add steps in the windows phone 8 slider I want my slider to accept only values 0,1,2,3,4.
Also I want the template to be discrete showing a little thin line in each value on the slider just like ease of access in Windows phone 8 settings.
The sliders should be like 4 rectangular thin boxes on which if I slide get fill,
Thanks in advance
Upvotes: 2
Views: 812
Reputation: 429
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Name="TotalPlanedLeave" Grid.ColumnSpan="2" Text="Total Planed Leaves :"></TextBlock>
<TextBlock Grid.Column="2" HorizontalAlignment="Left" Name="l1" Text="1" ></TextBlock>
</Grid>
<Slider Name="TotalPlanedLeaveS" ValueChanged="TotalPlanedLeaveS_ValueChanged" ></Slider>
in code behind
private void TotalPlanedLeaveS_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
l1.Text = (Convert.ToInt32(TotalPlanedLeaveS.Value)).ToString();
}
Upvotes: 0
Reputation: 29953
Instead of reaching out to third party controls, you could try registering an attached property to do the mathematical rounding for you. As a very quick and dirty example (that is probably way over the top for what needs to happen) you could create something like this.
public class SliderExtensions
{
public static readonly DependencyProperty IntegerValueProperty = DependencyProperty.RegisterAttached("IntegerValue", typeof(int), typeof(SliderExtensions), new PropertyMetadata(1));
public static void SetIntegerValue(DependencyObject element, int value)
{
((Slider)element).ValueChanged += (s, e) => { ((Slider)s).Value = Math.Round(((Slider)s).Value); };
}
public static int GetIntegerValue(DependencyObject element)
{
return (int)((Slider)element).Value;
}
}
and then use it in your Slider as follows.
<StackPanel>
<Slider x:Name="sld" Minimum="0" Maximum="4" SmallChange="1" helper:SliderExtensions.IntegerValue="0" />
<TextBlock Text="{Binding ElementName=sld, Path=Value}" />
</StackPanel>
Don't forget to add the "helper" namespace to your XAML, and that this is largely untested other than a very quick look.
Upvotes: 2
Reputation: 1435
using scroll viewer you can make slider or you can use telrik control.It gives good slider control, refer below link
hope it will help you
Upvotes: 1