Home > Enterprise >  C# WPF MediaElement Volume only switches between 0 to 100 and ignores the rest of the slider
C# WPF MediaElement Volume only switches between 0 to 100 and ignores the rest of the slider

Time:01-12

I have binded the media element volume and the slider's value and for some reason the volume is either 0 or 100. if the slider is all the way down(value = 0) its muting but if its anything else the volume is 100.

Media Element

<MediaElement x:Name="ME" Stretch="Fill"
              Volume="{Binding ElementName=VSlider,Path=Value,
    UpdateSourceTrigger=PropertyChanged}" MediaOpened="ME_MediaOpened"/>

Slider's code

<Slider x:Name="VSlider"
        Width="30" Height="{x:Static wsm:WindowSettings.wpHeight}" Maximum="100"
        Value="{Binding Source={x:Static wsm:WindowSettings.currentVolume }, Mode=OneWay}"
        TickFrequency="10" TickPlacement="BottomRight" 
        SmallChange="1" LargeChange="5" Orientation="Vertical"/>

CodePudding user response:

Because the MediaElement.Volume Property is defined as:

The media's volume represented on a linear scale between 0 and 1. The default is 0.5.

Divide all the settings by 100.

<Slider x:Name="VSlider"
   Maximum="1" TickFrequency="0.1" SmallChange="0.01" LargeChange="0.05"
   ...
/>

Note: these Slider properties are all double.

  •  Tags:  
  • Related