Class ProgressBar
Displays Value as a proportion of Minimum/Maximum, drawn as a track (this control's inherited Background/BorderBrush) with a FillBrush-colored fill growing from the left.
public class ProgressBar : Control, INotifyPropertyChanging, IBindingTarget, INotifyPropertyChanged, INotifyFocusChanged, IContainerLayout
- Inheritance
-
ProgressBar
- Implements
- Inherited Members
- Extension Methods
Remarks
Template-safe via a named template part: a Template that declares an element named
PART_Fill (of any type assignable to Border) has its fill logic wired to that
element instead of the built-in default fill - see OnApplyTemplate(). A template that declares
none still applies (the default fill keeps working, just detached from what's visually shown).
Constructors
ProgressBar()
Initializes a new instance of the ProgressBar class.
public ProgressBar()
Properties
FillBrush
Gets or sets the brush used to paint the filled portion of the bar.
public IBrush FillBrush { get; set; }
Property Value
Maximum
Gets or sets the value Value represents as a full bar.
public float Maximum { get; set; }
Property Value
Minimum
Gets or sets the value Value represents as an empty bar.
public float Minimum { get; set; }
Property Value
Value
public float Value { get; set; }
Property Value
Methods
ArrangeContent()
Handles custom arrange logic when overridden in any UIElement instance.
protected override void ArrangeContent()
Remarks
This method is called during the arrange pass to position and size the element's content within its final bounds. The element's position and size are already determined by the layout system and available in the ActualBounds property.
When implementing this method:
- Position child elements within the available space;
- Respect the element's padding when positioning content;
- Handle any content-specific layout requirements;
- Call Arrange() on child elements if needed.
MeasureContent()
Handles custom measure logic when overridden in any UIElement instance.
protected override Size MeasureContent()
Returns
Remarks
This method is called during the measure pass to determine the desired size of the element. The returned size should represent the natural size of the element's content, without considering any constraints, margins, or padding.
When implementing this method:
- Return the natural size needed to display the content;
- Do not include padding, margins, or borders in the returned size;
- Consider the content's actual dimensions (e.g., text length, image size);
- Return Empty if the element has no content.
OnApplyTemplate()
Called once, every time Template changes (in either direction - applied, cleared, or switched to a different template), right after Chrome and every decoration/content property have been fully re-wired for the new state.
protected override void OnApplyTemplate()
Remarks
Does nothing by default. A subclass that reaches into its own visual tree by reference - e.g. Slider wiring its drag logic directly to its thumb element - overrides this to call GetTemplateChild<T>(string) and repoint that reference to whatever the new Template (or, when reverting, the fresh default Border) actually provides, instead of hardcoding it once at construction. This is what actually makes a control "template-safe": until a control overrides this appropriately, applying a custom Template to it silently orphans whatever elements its own code still holds direct references to.