如何对Slider控件的每个值进行操作?

时间:2015-01-05 17:22:22

标签: c# xaml windows-phone-8

我在Windows Phone app 8.1中添加了一个Slider控件

控件包含5个值。我该如何对他们采取行动?

它是通过使用c#还是XAML来实现的?

我的滑块就是这样:

<Slider Header="Imposta difficoltà" x:Name="SliderDifficolta"  TickFrequency="1" StepFrequency="1" TickPlacement="Inline" Minimum="1" Maximum="5" Margin="0,190,0,251" Background="#FFD4BB18" LargeChange="10" Value="3" Foreground="#FFF8610B" SmallChange="0"  />

1 个答案:

答案 0 :(得分:0)

处理ValueChanged事件。 首先,您需要将处理程序(ValueChanged="ValueChangedHandler")添加到XAML标记:

<Slider Header="Imposta difficoltà" x:Name="SliderDifficolta"  TickFrequency="1" StepFrequency="1" TickPlacement="Inline" Minimum="1" Maximum="5" Margin="0,190,0,251" Background="#FFD4BB18" LargeChange="10" Value="3" Foreground="#FFF8610B" SmallChange="0" ValueChanged="ValueChangedHandler" />

然后在代码隐藏中写下事件处理程序:

private void ValueChangedHandler(object sender, RangeBaseValueChangedEventArgs e)
{
    string msg = String.Format("Current value: {0}", e.NewValue);
    this.textBlock1.Text = msg;
}