Results 1 to 9 of 9

Thread: [No Solution Found]Custom Progress Bar Max/Value problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2008
    Posts
    100

    [No Solution Found]Custom Progress Bar Max/Value problem

    I have made a custom template for a progress bar.

    Attached is a window XAML which you could simply add to a new project and see the problem.

    The problem is that the Value does not work with the Max value. The Value must go to the width of the progress bar. ie if the width is 300 and the max is 100 then the value at 100 will only a third full. How can i correct this to the default way progress bars work.

    Thanks guys in advice for any help. I am learning this stuff.
    Attached Files Attached Files
    Last edited by darbid; Oct 27th, 2010 at 04:22 AM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Aug 2008
    Posts
    100

    Re: Custom Progress Bar Max/Value problem

    the question is really that hard?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2008
    Posts
    100

    Re: Custom Progress Bar Max/Value problem

    Then would anyone like to explain me how the standard one works with the Value and Max Value.

  4. #4
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611

    Re: [No Solution Found]Custom Progress Bar Max/Value problem

    Your problem is that max isn't the width of the progressbar. If the width of the progressbar is 50, and the max is 100, You should devide the input by 2
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2008
    Posts
    100

    Re: [No Solution Found]Custom Progress Bar Max/Value problem

    Hey Thanks heaps for picking up the thread.

    Quote Originally Posted by Lightning View Post
    Your problem is that max isn't the width of the progressbar. If the width of the progressbar is 50, and the max is 100, You should devide the input by 2
    I assume you are talking in theory or did you look at my example (which by the way could be added to a project to see it working).

    If you are talking theory I am not sure about your answer. At the bottom of this page I read the following - http://msdn.microsoft.com/en-us/libr...ogressbar.aspx


    "ProgressBar overrides the metadata of the Maximum property and sets its default to 100. ProgressBar overrides the metadata of the Focusable property and sets its default to false. For more information, see Dependency Properties Overview."

  6. #6
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: [No Solution Found]Custom Progress Bar Max/Value problem

    If you want a Value of "100" to be 1/3 full, then you set the Maximum to be 300. The Width property, as Lightning points out, has nothing to do with the progress of the bar itself. Imagine what happens when someone wants the progress bar to take up a little less space on your screen: are you going to have to revalidate all your logic because the progress bar now goes from 0 to 84 because you changes the size of it on the UI?

    You can ignore the stuff you've quoted from the MSDN. That is just saying that for a ProgressBar, Maximum defaults to 100 (which is different to the default of its base class). You're explicitly setting the Maximum property in XAML, so the defaults are completely irrelevant.

    I'm completely clueless as to why you would want the Value to be based on screen units rather than, say, some unit relevant to your problem domain, but if you must tie the Maximum property to the Width property (p.s. what happens when you change the Orientation of the ProgressBar?) then you should be using data binding in the XAML.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2008
    Posts
    100

    Re: [No Solution Found]Custom Progress Bar Max/Value problem

    Quote Originally Posted by Evil_Giraffe View Post
    I'm completely clueless as to why you would want the Value to be based on screen units rather than, say, some unit relevant to your problem domain, but if you must tie the Maximum property to the Width property (p.s. what happens when you change the Orientation of the ProgressBar?) then you should be using data binding in the XAML.
    Ahh... Looks like I asked the question wrong. Exactly what you understand I want to do is exactly what I do not want to do. I have edited the standard progress bar and now the value is based on the width of the prgress bar and not % of the progress bar.

    Thus I have the exact problem you forsee. If I change the width of the bar I have to change my code to deal with a different Value.

  8. #8
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: [No Solution Found]Custom Progress Bar Max/Value problem

    Ooooooooh I see the problem.
    You've bound the width of the rectangle that is the progress bar fill to the Value property:
    Code:
    <Grid Margin="1" x:Name="DeterminateRoot">
        <Rectangle 
            HorizontalAlignment="Left"
            Margin="1,.1,.1,.1"
            x:Name="ProgressBarIndicator"
            Fill="{TemplateBinding Foreground}"
            StrokeThickness="0.5"
            RadiusX="25"
            RadiusY="25"
            Width="{TemplateBinding Value}" />
    </Grid>
    You'll need to convert that value to a width using a MultiValueConverter. I wouldn't be surprised if there was a built in converter that can do this for you, but if not, simply create a new one that takes the Value, Maximum (and Minimum for completeness sake - the calculation could simply assume the Minimum stays at 0, I suppose) of the ProgressBar and the Width of the ProgressBar, then return the width that the Rectangle needs to be.

    That feels a bit of a hack to me, though. I would suggest you have a quick look at how the standard ProgressBar template works. In Expression Blend, drop a ProgressBar into a new project, then from the Object menu select Edit Template > Edit a Copy... This will place the default control template into the XAML you're currently editing for you to examine. They probably have a more elegant way of handling this scenario than the way I came up with.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Aug 2008
    Posts
    100

    Re: [No Solution Found]Custom Progress Bar Max/Value problem

    Thank you very much for taking the time. I have been unable to test/work it out but as soon as I do I will give feedback here.

    Thank you again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width