WPF FrameworkElement Width, MinWidth, MaxWidth and ActualWidth

17. September 2010

 

There are 3 Properties which specifies the Width Information for FrameworkElement (parent class for WPF Controls). Width , MinWidth and MaxWidth. As the name says, With Property specifies the Width of the Element and MinWidth and MaxWidth specifies the constraints for the Width of the element. If there is any conflict in these values, MinWidth takes higher priority and then MaxWidth, and finally if both of these values are within bounds, Width. If you Apply all these properties and if you want to check the rendered Width, then you can use ActualWidth Property (which is read only property).

In short, 

 

  • Width is the requested Width and MinWidth, MaxWidth are constraints for the Width.
  • ActualWidth is the rendered size. 

 

The same Applies to Height, MinHeight, MaxHeight and ActualHeight Properties.

 

Here is Example, 

Scenario 1:

If you set Width = 75, MinWidth = 25, MaxWidth = 100

and the calculated width (ActualWidth) = 75 (Width value is used as the value set for Width is withing the bounds of Min and Max Widths)

 

Scenario 2:

if you set Width = 25, MinWidth = 50, MaxWidth = 75, 

and the calculated width (ActualWidth) = 50 (Min Width takes precedence as the requested width is smaller than Min Width)

 

Scenario 3:

if you set Width =100, MinWidth = 50, MaxWidth = 75, 

and the calculated width (ActualWidth) = 75 (Max Width takes precedence as the requested width satisfies Min Width and is bigger than Max Width)


Hope this helps.

 

.Net Tips, Technical, wpf , , , ,

blog comments powered by Disqus