Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

FrameworkElement.MinWidth Property

Gets or sets the minimum width constraint of the element. This is a dependency property.

Namespace: System.Windows
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[TypeConverterAttribute(typeof(LengthConverter))] 
[LocalizabilityAttribute(LocalizationCategory::None, Readability=Readability::Unreadable)] 
public:
property double MinWidth {
	double get ();
	void set (double value);
}
/** @property */
public double get_MinWidth ()

/** @property */
public void set_MinWidth (double value)

public function get MinWidth () : double

public function set MinWidth (value : double)

<object MinWidth="double"/>
- or -
<object MinWidth="qualifiedDouble"/>
 double   Double  String representation of a Double value equal to or greater than 0.0. This is interpreted as a device-independent unit (1/96th inch) measurement. Strings need not explicitly include decimal points. For instance a value of 1 is acceptable.  The same Double range restrictions as mentioned in the Property Value section apply.  qualifiedDouble  A double value as described above, followed by one of the following unit declaration strings: px, in, cm, pt.  px (default) is device-independent units (1/96th inch per unit)  in is inches; 1in==96px  cm is centimeters; 1cm==(96/2.54) px  pt is points; 1pt==(96/72) px 

Property Value

The minimum width of the element, in device-independent units (1/96th inch per unit). The default value is 0.0. This value can be any value equal to or greather than 0.0. However, PositiveInfinity is not valid, nor is Double.NaN.

Identifier field

MinWidthProperty

Metadata properties set to true

AffectsMeasure

This is one of three properties on FrameworkElement that specify width information. The other two are Width and MaxWidth. If there is a conflict between these values, the order of application for actual width determination is first MinWidth must be honored, then MaxWidth, and finally if each of these are within bounds, Width.

The value restrictions on the Double value are enforced by a ValidateValueCallback mechanism. If you attempt to set an invalid value , a runtime exception is raised.

This example visually shows the differences in rendering behavior among the four width-related properties in Windows Presentation Foundation (WPF).

The FrameworkElement class exposes four properties that describe the width characteristics of an element. These four properties can conflict, and when they do, the value that takes precedence is determined as follows: the MinWidth value takes precedence over the MaxWidth value, which in turn takes precedence over the Width value. The fourth property, ActualWidth, is read-only.

The following Extensible Application Markup Language (XAML) examples draw a Rectangle element (rect1) as a child of Canvas. You can change the width properties of a Rectangle by using a series of ListBoxes that represent the property values of MinWidth, MaxWidth, and Width. In this manner, the precedence of each property is visually displayed.

<Canvas Height="200" MinWidth="200" Background="#b0c4de" VerticalAlignment="Top"  HorizontalAlignment="Center" Name="myCanvas">
    <Rectangle HorizontalAlignment="Center" Canvas.Top="50" Canvas.Left="50"  Name="rect1" Fill="#4682b4" Width="100" Height="100"/>
</Canvas>

...

  <TextBlock Grid.Row="1" Grid.Column="0" Margin="10,0,0,0" TextWrapping="Wrap">Set the Rectangle Width:</TextBlock>
  <ListBox Grid.Column="1" Grid.Row="1" Margin="10,0,0,0" Width="50" Height="50" SelectionChanged="changeWidth">
    <ListBoxItem>25</ListBoxItem>
    <ListBoxItem>50</ListBoxItem>
    <ListBoxItem>75</ListBoxItem>
    <ListBoxItem>100</ListBoxItem>
    <ListBoxItem>125</ListBoxItem>
    <ListBoxItem>150</ListBoxItem>
    <ListBoxItem>175</ListBoxItem>
    <ListBoxItem>200</ListBoxItem>
    <ListBoxItem>225</ListBoxItem>
    <ListBoxItem>250</ListBoxItem>
  </ListBox>

  <TextBlock Grid.Row="1" Grid.Column="2" Margin="10,0,0,0" TextWrapping="Wrap">Set the Rectangle MinWidth:</TextBlock>
  <ListBox Grid.Column="3" Grid.Row="1" Margin="10,0,0,0" Width="50" Height="50" SelectionChanged="changeMinWidth">
    <ListBoxItem>25</ListBoxItem>
    <ListBoxItem>50</ListBoxItem>
    <ListBoxItem>75</ListBoxItem>
    <ListBoxItem>100</ListBoxItem>
    <ListBoxItem>125</ListBoxItem>
    <ListBoxItem>150</ListBoxItem>
    <ListBoxItem>175</ListBoxItem>
    <ListBoxItem>200</ListBoxItem>
    <ListBoxItem>225</ListBoxItem>
    <ListBoxItem>250</ListBoxItem>
</ListBox>      
   
  <TextBlock Grid.Row="1" Grid.Column="4" Margin="10,0,0,0" TextWrapping="Wrap">Set the Rectangle MaxWidth:</TextBlock>
  <ListBox Grid.Column="5" Grid.Row="1" Margin="10,0,0,0" Width="50" Height="50" SelectionChanged="changeMaxWidth">
    <ListBoxItem>25</ListBoxItem>
    <ListBoxItem>50</ListBoxItem>
    <ListBoxItem>75</ListBoxItem>
    <ListBoxItem>100</ListBoxItem>
    <ListBoxItem>125</ListBoxItem>
    <ListBoxItem>150</ListBoxItem>
    <ListBoxItem>175</ListBoxItem>
    <ListBoxItem>200</ListBoxItem>
    <ListBoxItem>225</ListBoxItem>
    <ListBoxItem>250</ListBoxItem>  
  </ListBox>

The following code-behind examples handle the events that the SelectionChanged event raises. Each custom method takes the input from the ListBox, parses the value as a Double, and applies the value to the specified width-related property. The width values are also converted to a string and written to a TextBlock element named txt1.

No code example is currently available or this language may not be supported.

For the complete sample, see Width Properties Sample.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.