Custom progress bar label text via binding

Posted by Alexander K on Stack Overflow See other posts from Stack Overflow or by Alexander K
Published on 2010-05-31T12:40:27Z Indexed on 2010/05/31 13:32 UTC
Read the original article Hit count: 187

I was playing with progress bar customization in Silverlight application. What I want to reach is to have progress bar label to show current its state in the following format: "Value / Maximum". So, user will see what is the current value, and what is the maximum possible value. Here is a style for progress bar I use:

<Style x:Key="ProgressBarStyle" TargetType="ProgressBar">
        <Setter Property="Width" Value="97.21" />
        <Setter Property="Height" Value="19" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ProgressBar">
                    <Canvas x:Name="LevelField" Width="99" Height="21">
                        ...
                    <TextBlock ... DataContext="{TemplateBinding Value}" Text="{Binding Converter={StaticResource DecNumberToStringConverter}}"/>
                    </Canvas>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

The way I want to implement this, is to have a value converter, that will convert current value and maximum possible into the proper string. It does work properly, if it is written like above. However, I also need to provide ConverterParameter for Convertor, but not sure how to make it. When I write like this: , ConvertParameter={Binding Maximum}, it shows error on start, that Text attribute is not found in TextBlock. I was also trying to set DataContext as {RelativeSource Self}, but then it didn't displays error that DataContext attribute is not found.

How to make the described progress bar label properly?

© Stack Overflow or respective owner

Related posts about Silverlight

Related posts about databinding