0

I am using C# and WPF for my GUI. My goal is to display a string in the progress bar that I get from a text box. I wish to display 1 character every 200ms so thtat the string animates to completion. How can I display a string in the progress bar in WPF and how can I animate it's display?

3
  • How are you currently writing the code? There's many different ways of doing this
    – DJ Burb
    Nov 20, 2012 at 21:25
  • what do you mean by how are u currently writing the code? im student and this is what my teacher ask for me to do. I cant do it with textbox that change...
    – DorZ11
    Nov 23, 2012 at 13:00
  • in other words, what have you tried so far? Do you have any code that you have written? Show your code so that we can analyze it and maybe help.
    – DJ Burb
    Nov 26, 2012 at 20:22

3 Answers 3

0

Have you tried the Text property?

MSDN

1
  • Wrong ProgressBar. That is WinForms, this is WPF. Nov 20, 2012 at 21:26
0

Subscribe to ProgressChanged but don't use a ProgressBar. Just update a TextBox with new text.

0

You could subclass the ProgressBar, add a Text dependency property and then create a template for it that will include a TextBox bound to the Text property using a converter that will return a substring based on the Value of the ProgressBar (or you could just handle it within the class itself).

Alternatively, there are various ways you could fake it by overlaying a rectangle with a gradient brush over a textblock. The brush should go from transparent to opaque whatever your background color is, and the position of the gradient is tied to the progess bar's value.

Here's a real quick and dirty example of faking it:

<Grid>
    <ProgressBar Name="MyBar" Minimum="0" Maximum="1" Value="0.6">

    </ProgressBar>

    <Grid>
        <TextBlock>Some Text that will be covered depending on the value of the progress bar</TextBlock>
        <Rectangle>
            <Rectangle.Fill>
                <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
                    <GradientStop Offset="0" Color="Transparent"/>
                    <GradientStop Offset="{Binding ElementName=MyBar, Path=Value}" Color="Transparent"/>
                    <GradientStop Offset="{Binding ElementName=MyBar, Path=Value}" Color="White"/>
                    <GradientStop Offset="1" Color="White"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
    </Grid>
</Grid>

If you mess with the value of the ProgressBar, you'll move the transition between transparent and opaque in the gradient brush.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.