WP8 滑块的问题 [英] Problems with WP8 Slider
本文介绍了WP8 滑块的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 XAML:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Slider Name="sldLength" Margin="0 0 0 0" Grid.Column="0"
Minimum="5" Maximum="30" SmallChange="1" LargeChange="1"
Value="10" ValueChanged="sldLength_ValueChanged"/>
<TextBlock Name="tblLength" Margin="0 10 5 0" Text="10" Grid.Column="1"
FontSize="{StaticResource PhoneFontSizeMediumLarge}"/>
</Grid>
我的代码开始了:
private void sldLength_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
tblLength.Text = e.NewValue.ToString();
}
2个问题:
- 在加载应用程序时触发 ValueChanged 事件,这不是问题,但由于某种原因,在事件触发时 tblLength 为 NULL 并且这会引发异常,我将其包装在 if 语句检查该 NULL,但这肯定不是问题吧?
- Slider 不会以 1 的增量变化,即使 SmallChange 和 LargeChange 设置为 1.如何修复?
- ValueChanged event fires when the application is loaded, this is not a problem, but for some reason at the time of the event firing tblLength is NULL and this throws an exception, I have wrapped it in an if statement checking for that NULL, but this surely should not be the issue right?
- Slider does not change in the increments of 1, even though SmallChange and LargeChange are set to 1. How could that be fixed?
感谢您的帮助...
--编辑--
使用 Chepene 建议解决了问题 1.
用小丑事件处理程序解决了问题 2:
Solved problem 1 with Chepene suggestion.
Solved problem 2 with little cheeky event handler:
private void sldLength_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
((Slider)sender).Value = Math.Round(((Slider)sender).Value);
}
推荐答案
您可以使用绑定.像这样:
You can use Bindings. Smth like this:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Slider Name="sldLength" Margin="0 0 0 0" Grid.Column="0"
Minimum="5" Maximum="30" SmallChange="1" LargeChange="1"
Value="10"/>
<TextBlock Name="tblLength" Margin="0 10 5 0" Text="{Binding ElemantName=sldLength, Path=Value}" Grid.Column="1"
FontSize="{StaticResource PhoneFontSizeMediumLarge}"/>
</Grid>
此处 tblLength 从 sldLength 的值中获取其文本.
Here tblLength takes its text from the value of sldLength.
这篇关于WP8 滑块的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文