Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 485191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:22:35+00:00 2026-05-13T01:22:35+00:00

Hope someone can help. I have a simple scenario where clicking checkboxes is driving

  • 0

Hope someone can help.
I have a simple scenario where clicking checkboxes is driving a progress bar in WPF. The checkboxes are contained in a UserControl and the Progress bar is in a simple WPF client window.
On the user control I am using two dependency properties:
1) the existing Tag property has the value I wish to bind to the progress bar value and
2) a DP called CbCount which represents the total number of checkboxes.

The problem:
When the application runs the progress bar’s progress shows as being 100% complete even though via Snoop I can see the value is in fact 0. Clicking on the checkboxes everything works fine as expected.

Code:
UserControl – within namespace ProgBarChkBxs:

public partial class ucChkBoxes : UserControl
{
    #region CbCount

    public static readonly DependencyProperty CbCountProperty =
        DependencyProperty.Register("CbCount", typeof(double), typeof(ucChkBoxes),
            new FrameworkPropertyMetadata((double)0));

    /// <summary>
    /// Gets or sets the CbCount property.  This dependency property
    /// indicates the number of checkBoxes
    /// </summary>
    public double CbCount
    {
        get { return (double)GetValue(CbCountProperty); }
        private set { SetValue(CbCountProperty, value); }
    }

    #endregion

    double _totalCount = 0;
    double _numberChecked = 0;
    double DEFAULT = 0;

    public ucChkBoxes()
    {
        InitializeComponent();
        this.Tag = DEFAULT;
        this.Loaded += new RoutedEventHandler(ucChkBoxes_Loaded);
    }

    void ucChkBoxes_Loaded(object sender, RoutedEventArgs e)
    {
        if (this.ourContainer.Children.Count != 0)
        {
            _totalCount = this.ourContainer.Children.Count;
        }
        this.CbCount = (double)_totalCount;
    }

    private void CheckBox_Checked(object sender, RoutedEventArgs e)
    {
        if (e.OriginalSource.GetType() == typeof(CheckBox))
        {
            CheckBox cb = (CheckBox)e.OriginalSource;
            if (cb.IsChecked == true) { _numberChecked++; }
            if (cb.IsChecked != true) { _numberChecked--; }

            //simple POC progress metric
            this.Tag = (double)(_numberChecked / _totalCount * _totalCount);
        }
    }
}

XAML:

<UserControl x:Class="ProgBarChkBxs.ucChkBoxes"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="Auto" Width="Auto">
    <StackPanel>
        <TextBlock  Text="Please select options" ></TextBlock>
        <StackPanel Name="ourContainer"
                    CheckBox.Checked="CheckBox_Checked"
                    CheckBox.Unchecked="CheckBox_Checked">
            <CheckBox>Fruit Juice</CheckBox>
            <CheckBox>Coffee</CheckBox>
            <CheckBox>Toast</CheckBox>
            <CheckBox>Cereal</CheckBox>
            <CheckBox>Grapefruit</CheckBox>
        </StackPanel>
    </StackPanel>
</UserControl>

The Client which just has the databindings is a simple window – the local namespace below refers to the project namespace xmlns:local=”clr-namespace:ProgBarChkBxs”, the meat of the code is:

<StackPanel>
    <local:ucChkBoxes  x:Name="chkBoxes"/>
    <ProgressBar Name="pb" Background="Azure" Minimum="0" Height="30"
                 Value="{Binding ElementName=chkBoxes,Path=Tag }"
                 Maximum="{Binding ElementName=chkBoxes,Path=CbCount }"
    />
</StackPanel>

The really weird thing is if within the DP definition of the CbCount if I change the FrameworkPropertyMetadata to a really small value to say (double)0.001 the problem goes away.

I am running this on XP.

All help gratefully received – thanks.

Update:
I have been digging into this again as it gnaws at my sole (who said get a life!)

Things I did:

1) Adding a slider which also like progressBar inherits from RangeBase gives me the expected behaviour.

2) Spinning up reflector I can see the static ctor for ProgressBar sets the default value first to 100,
RangeBase.MaximumProperty.OverrideMetadata(typeof(ProgressBar), new FrameworkPropertyMetadata(100.0)); Should AffectMeasure?
whereas in the slider:
RangeBase.MaximumProperty.OverrideMetadata(typeof(Slider), new FrameworkPropertyMetadata(10.0, FrameworkPropertyMetadataOptions.AffectsMeasure));

3) So we need another layout pass after a I set the ProgressBar.Value
Going back to my simple POC application if within a the progressBar loaded handler in the client window I jig the layout on the first run through:

this.Width += 1; //trigger another layout pass

Then, hey, presto it works.

So is this a bug?

I still do not fully understand though how the progressBar value which is calculated from Minimum and Maximum values is affected in this way and not the Slider – the default value of Maximum appears to be having an effect and it looks as if the ProgressBar default should affect the measure pass. (missing FrameworkPropertyMetadataOptions.AffectsMeasure.)

Can anyone help, either confirm my thinking or explain what is really happening here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T01:22:36+00:00Added an answer on May 13, 2026 at 1:22 am

    ucChkBoxes_Loaded method gets called after the progressbar gets rendered. When the progressbar gets rendered, Tag and CbCount are zero meaning that the progressbar will have min=0, max=0 and value=0, which is correctly drawn as as 100%. If you invalidate the progressbar, for example resize window it will show as 0%, since now Tag and CbCount have been updated.

    To fix, don’t wait until ucChkBoxes.Loaded() is called to initialize your control, do it in constructor or when initializing the DP for CbCount, for example.

    public ucChkBoxes()
    {
        InitializeComponent();
        this.Tag = DEFAULT;
        if (this.ourContainer.Children.Count != 0)
        {
            _totalCount = this.ourContainer.Children.Count;
        }
        this.CbCount = (double)_totalCount;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i hope someone can help, In basic terms i am trying to stop
I have an android XML and I am trying to get the ads to
I'm starting to learn Rails. I'm using Rails 3. In my simple App, I
I run a small blog network and on this I have a page where
Im trying to do a very simple thing (showing a populated listView) but im
I have scoured the internet looking for a solution to this and I am
I have a cck-node with some node-references like PDF-files, videos and so on. Now
I find examples and tutorials about models and about validation. And I places that
I've been programming with Java for Android quite some while now. Since performance is
I'm pretty new to Objective C but things are progressing well. However, I think

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.