I'm having problems on the toggle switch and the slider.
The value of the slider is used to increase or decrease the volume of my media element.
However, let's say if I set the value of the slider to '50' and I toggle the switch to 'off' my media element.
How do I capture the previous value from the slider when I toggle the switch back to 'on'?
At the moment, I set the value for slider to '100' when sw_music.IsOn
XAML:
Code-Behind:
The value of the slider is used to increase or decrease the volume of my media element.
However, let's say if I set the value of the slider to '50' and I toggle the switch to 'off' my media element.
How do I capture the previous value from the slider when I toggle the switch back to 'on'?
At the moment, I set the value for slider to '100' when sw_music.IsOn
XAML:
<Slider x:Name="slider" HorizontalAlignment="Left" VerticalAlignment="Top" Width="154" Margin="45,0,0,0" Height="42" Maximum="100" Value="100"/> <ToggleSwitch x:Name="sw_music" Header="SOUND" IsOn="{Binding Value, ElementName=slider}"/> <MediaElement x:Name="Intro_Sound" Source="SoundEffects/Intro.wav" Volume="{Binding Value, ElementName=slider}"/>
Code-Behind:
private void sw_music_Toggle(object sender, RoutedEventArgs e) { if(slider.Value >= 1) { if (sw_music.IsOn) { slider.Value = 100; Intro_Sound.Play(); } else { slider.Value = 0; Intro_Sound.Stop(); } if(slider.Value > 1) { Intro_Sound.Play(); sw_music.IsOn = true; } } } private void Slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e) { Intro_Sound.Volume = (slider.Value) / 100; if (slider.Value == 0) { sw_music.IsOn = false; } else { sw_music.IsOn = true; } }