ProgressBar not updating on change to Maximum through binding

后端 未结 2 1194
甜味超标
甜味超标 2021-01-21 05:36


        
2条回答
  •  隐瞒了意图╮
    2021-01-21 06:19

    It looks like the bar size is calculated in the private method ProgressBar.SetProgressBarIndicatorLength. It's only called from OnValueChanged, OnTrackSizeChanged, and OnIsIndeterminateChanged.

    You could call SetProgressBarIndicatorLength through reflection, or cycle one of the properties that causes it to be called. This is lame, but it doesn't look like the ProgressBar was designed so that the Maximum and Minimum would be changed in mid-progress.

    Regardless of which method you choose, you can figure out when the Maximum property changes by using DependencyPropertyDescriptor.AddValueChanged:

    DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(ProgressBar.MaximumProperty, typeof(ProgressBar)));
    if (dpd != null)
    {
       dpd.AddValueChanged(myProgressBar, delegate
       {
          // handle Maximum changes here
       });
    }
    

提交回复
热议问题