Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<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"/>

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading