我正在从我的音乐播放器中为Windows 8创建音量滑块,但它抛出异常说:
'System.ArgumentException' occurred in Microsoft.Phone.ni.dll but was not handled in user code
我的代码:
<Slider x:Name="VolumeSlider" HorizontalAlignment="Left" Margin="18,563,0,0" VerticalAlignment="Top" Width="245" RenderTransformOrigin="0.467,-0.833" ValueChanged="ChangeMediaVolume" />
和
// Change the volume of the media.
private void ChangeMediaVolume(object sender, RoutedPropertyChangedEventArgs<double> args)
{
{
BackgroundAudioPlayer.Instance.Volume = (double)VolumeSlider.Value;
}
}
void InitializePropertyValues()
{
BackgroundAudioPlayer.Instance.Volume = (double)VolumeSlider.Value;
}
答案 0 :(得分:6)
您没有设置滑块的范围。默认范围是0到10,但是BackgroundAutoPlayer.Instance.Volume
需要介于0和1之间的值,默认值为0.85,因为您可以阅读here
使用此
<Slider x:Name="VolumeSlider" HorizontalAlignment="Left" Margin="18,563,0,0" VerticalAlignment="Top" Width="245" RenderTransformOrigin="0.467,-0.833" Maximum="1" ValueChanged="ChangeMediaVolume" />
也许你想设置SmallChange="0.01"
和LargeChange="0.1"
希望这有帮助