Search code examples
silverlightxamlbindingexpression-blend

Bind Slider Value to ProgressBar effectively?


So what I would like to do is control a Progressbar width by way of a slider with just xaml. What's below sort of works, but it only increases the ProgressBar's value slightly. After playing with the min/max, not sure where my fault is. I saw workarounds using a rectangle and some codebehind, but I'd like to interact with the ProgressBar specifically for this example. Thanks for any shared insight!

<Slider Orientation="Vertical" 
        Value="{Binding ElementName=progress, Path=Value, Mode=TwoWay}" />
<ProgressBar x:Name="progress" 
         Height="20" 
         IsIndeterminate="False" Minimum="0" Maximum="100"/>

Solution

  • Just set the Minimum and Maximum on the Slider to match the ProgressBar

    <Slider Orientation="Vertical" 
            Value="{Binding ElementName=progress, Path=Value, Mode=TwoWay}" 
            Minimum="0" Maximum="100"
    />
    
    <ProgressBar x:Name="progress" 
             Height="20" 
             IsIndeterminate="False" Minimum="0" Maximum="100"/>
    

    or bind the min/max if required

    <Slider Orientation="Vertical" 
        Value="{Binding ElementName=progress, Path=Value, Mode=TwoWay}" 
        Minimum="{Binding ElementName=progress, Path=Minimum}" 
        Maximum="{Binding ElementName=progress, Path=Maximum}"
    />