Windows Phone 8中的音量滑块

时间:2013-06-20 17:03:14

标签: windows-phone-7 windows-phone-8

我正在从我的音乐播放器中为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;
    }

1 个答案:

答案 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"

希望这有帮助