1 <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3 Title="ActualWidth Sample"
4 x:Class="ActualWidth_Samp.Page1"
7 <TabControl MinHeight="500" MaxHeight="700" MinWidth="400">
8 <TabItem Style="{StaticResource TabStyle}" Header="Width Properties Sample" IsSelected="true">
10 <TextBlock Style="{StaticResource HeaderStyle}">Width Properties Sample</TextBlock>
12 <TextBlock Style="{StaticResource mainContentStyle}">Four properties are exposed on FrameworkElement that describe an element's Width characteristics. It is possible for these values to be in conflict. This example demonstrates how those conflicts between values are resolved.</TextBlock>
17 <TabItem Name="xaml" Style="{StaticResource TabStyle}" Header="XAML"></TabItem>
18 <TabItem Name="xamlcsharp" Style="{StaticResource TabStyle}" Header="XAML + C#">
19 <TabControl TabStripPlacement="Right" Height="500">
20 <TabItem Name="xcsharpCheck" Style="{StaticResource TabStyle2}" Header="XAML">
21 <ScrollViewer HorizontalScrollBarVisibility="Visible">
22 <TextBox Style="{StaticResource CodeSnippetParagraph}" xml:space="preserve">
24 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
25 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
26 x:Class="Width_MinWidth_MaxWidth.Window1"
27 Title="Width Properties Sample">
28 <Border BorderBrush="Black" BorderThickness="2" Background="White">
29 <StackPanel Margin="10">
31 <TextBlock FontSize="20" DockPanel.Dock="Top">Width Properties Sample</TextBlock>
32 <TextBlock TextWrapping="Wrap" Margin="0,0,0,10">Four properties are exposed on FrameworkElement that describe an element's Width characteristics. It is possible for these values to be in conflict. This example demonstrates how those conflicts between values are resolved.</TextBlock>
33 <TextBlock TextWrapping="Wrap" Margin="0,0,0,10">If viewed on a continuum, MinWidth value takes precedence over MaxWidth value, which in turn takes precedence over the Width value. This is best demonstrated visually:</TextBlock>
34 <Canvas Height="200" MinWidth="200" Background="#b0c4de" VerticalAlignment="Top" HorizontalAlignment="Center" Name="myCanvas">
35 <Rectangle HorizontalAlignment="Center" Canvas.Top="50" Canvas.Left="50" Name="rect1" Fill="#4682b4" Width="100" Height="100"/>
37 <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
38 <Button Name="Button1" Click="clipRect" Margin="0,5,5,5">Canvas.ClipToBounds="True"</Button><Button Name="Button2" Margin="0,5,5,5" Click="unclipRect">Canvas.ClipToBounds="False"</Button>
43 <ColumnDefinition Width="Auto"/>
44 <ColumnDefinition Width="Auto"/>
45 <ColumnDefinition Width="Auto"/>
46 <ColumnDefinition Width="Auto"/>
47 <ColumnDefinition Width="Auto"/>
48 <ColumnDefinition Width="Auto"/>
49 <TextBlock Grid.Row="0" FontSize="14" FontWeight="Bold" Grid.ColumnSpan="6" HorizontalAlignment="Center" Margin="0,15,0,15" TextWrapping="Wrap">
50 Use the ListBoxes below to manipulate the various Width related properties of the Rectangle above.</TextBlock>
51 <TextBlock Grid.Row="1" Grid.Column="0" Margin="10,0,0,0" TextWrapping="Wrap">Set the Rectangle Width:</TextBlock>
52 <ListBox Grid.Column="1" Grid.Row="1" Margin="10,0,0,0" Width="50" Height="50" SelectionChanged="changeWidth">
53 <ListBoxItem>25</ListBoxItem>
54 <ListBoxItem>50</ListBoxItem>
55 <ListBoxItem>75</ListBoxItem>
56 <ListBoxItem>100</ListBoxItem>
57 <ListBoxItem>125</ListBoxItem>
58 <ListBoxItem>150</ListBoxItem>
59 <ListBoxItem>175</ListBoxItem>
60 <ListBoxItem>200</ListBoxItem>
61 <ListBoxItem>225</ListBoxItem>
62 <ListBoxItem>250</ListBoxItem>
65 <TextBlock Grid.Row="1" Grid.Column="2" Margin="10,0,0,0" TextWrapping="Wrap">Set the Rectangle MinWidth:</TextBlock>
66 <ListBox Grid.Column="3" Grid.Row="1" Margin="10,0,0,0" Width="50" Height="50" SelectionChanged="changeMinWidth">
67 <ListBoxItem>25</ListBoxItem>
68 <ListBoxItem>50</ListBoxItem>
69 <ListBoxItem>75</ListBoxItem>
70 <ListBoxItem>100</ListBoxItem>
71 <ListBoxItem>125</ListBoxItem>
72 <ListBoxItem>150</ListBoxItem>
73 <ListBoxItem>175</ListBoxItem>
74 <ListBoxItem>200</ListBoxItem>
75 <ListBoxItem>225</ListBoxItem>
76 <ListBoxItem>250</ListBoxItem>
79 <TextBlock Grid.Row="1" Grid.Column="4" Margin="10,0,0,0" TextWrapping="Wrap">Set the Rectangle MaxWidth:</TextBlock>
80 <ListBox Grid.Column="5" Grid.Row="1" Margin="10,0,0,0" Width="50" Height="50" SelectionChanged="changeMaxWidth">
81 <ListBoxItem>25</ListBoxItem>
82 <ListBoxItem>50</ListBoxItem>
83 <ListBoxItem>75</ListBoxItem>
84 <ListBoxItem>100</ListBoxItem>
85 <ListBoxItem>125</ListBoxItem>
86 <ListBoxItem>150</ListBoxItem>
87 <ListBoxItem>175</ListBoxItem>
88 <ListBoxItem>200</ListBoxItem>
89 <ListBoxItem>225</ListBoxItem>
90 <ListBoxItem>250</ListBoxItem>
94 <TextBlock Name="txt1"/>
95 <TextBlock Name="txt2"/>
96 <TextBlock Name="txt3"/>
97 <TextBlock Name="txt4"/>
98 <TextBlock Name="txt5"/>
108 <TabItem Style="{StaticResource TabStyle2}" Header="C#">
110 <TextBox Style="{StaticResource CodeSnippetParagraph}" xml:space="preserve">
112 using System.Windows;
113 using System.Windows.Media;
114 using System.Windows.Controls;
115 using System.Windows.Documents;
117 namespace Width_MinWidth_MaxWidth
119 public partial class Window1 : Window
121 public void changeWidth(object sender, RoutedEventArgs args)
123 ListBoxItem li = ((sender as ListBox).SelectedItem as ListBoxItem);
124 Double sz1 = Double.Parse(li.Content.ToString());
126 rect1.UpdateLayout();
127 txt1.Text = "ActualWidth is set to " + rect1.ActualWidth;
128 txt2.Text = "Width is set to " + rect1.Width;
129 txt3.Text = "MinWidth is set to " + rect1.MinWidth;
130 txt4.Text = "MaxWidth is set to " + rect1.MaxWidth;
132 public void changeMinWidth(object sender, RoutedEventArgs args)
134 ListBoxItem li = ((sender as ListBox).SelectedItem as ListBoxItem);
135 Double sz1 = Double.Parse(li.Content.ToString());
136 rect1.MinWidth = sz1;
137 rect1.UpdateLayout();
138 txt1.Text = "ActualWidth is set to " + rect1.ActualWidth;
139 txt2.Text = "Width is set to " + rect1.Width;
140 txt3.Text = "MinWidth is set to " + rect1.MinWidth;
141 txt4.Text = "MaxWidth is set to " + rect1.MaxWidth;
143 public void changeMaxWidth(object sender, RoutedEventArgs args)
145 ListBoxItem li = ((sender as ListBox).SelectedItem as ListBoxItem);
146 Double sz1 = Double.Parse(li.Content.ToString());
147 rect1.MaxWidth = sz1;
148 rect1.UpdateLayout();
149 txt1.Text = "ActualWidth is set to " + rect1.ActualWidth;
150 txt2.Text = "Width is set to " + rect1.Width;
151 txt3.Text = "MinWidth is set to " + rect1.MinWidth;
152 txt4.Text = "MaxWidth is set to " + rect1.MaxWidth;
155 public void clipRect(object sender, RoutedEventArgs args)
157 myCanvas.ClipToBounds = true;
158 txt5.Text = "Canvas.ClipToBounds is set to " + myCanvas.ClipToBounds;
160 public void unclipRect(object sender, RoutedEventArgs args)
162 myCanvas.ClipToBounds = false;
163 txt5.Text = "Canvas.ClipToBounds is set to " + myCanvas.ClipToBounds;
174 <TabItem Name="xamlvb" Style="{StaticResource TabStyle}" Header="XAML + Visual Basic.NET">
175 <TabControl TabStripPlacement="Right">
176 <TabItem Name="xvbCheck" Style="{StaticResource TabStyle2}" Header="XAML"></TabItem>
177 <TabItem Style="{StaticResource TabStyle2}" Header="VB.NET"></TabItem>
180 <TabItem Name="csharp" Style="{StaticResource TabStyle}" Header="C#"></TabItem>
182 <TabItem Name="vb" Style="{StaticResource TabStyle}" Header="Visual Basic.NET"></TabItem>
184 <TabItem Name="managedcpp" Style="{StaticResource TabStyle}" Header="Managed C++"></TabItem>
186 <TabItem Style="{StaticResource TabStyle}" Header="Preview Sample">
187 <Border BorderBrush="Black" BorderThickness="2" Background="White">
188 <StackPanel Margin="10">
190 <TextBlock FontSize="20" DockPanel.Dock="Top">Width Properties Sample</TextBlock>
191 <TextBlock TextWrapping="Wrap" Margin="0,0,0,10">Four properties are exposed on FrameworkElement that describe an element's Width characteristics. It is possible for these values to be in conflict. This example demonstrates how those conflicts between values are resolved.</TextBlock>
192 <TextBlock TextWrapping="Wrap" Margin="0,0,0,10">If viewed on a continuum, MinWidth value takes precedence over MaxWidth value, which in turn takes precedence over the Width value. This is best demonstrated visually:</TextBlock>
193 <Canvas Height="200" MinWidth="200" Background="#b0c4de" VerticalAlignment="Top" HorizontalAlignment="Center" Name="myCanvas">
194 <Rectangle HorizontalAlignment="Center" Canvas.Top="50" Canvas.Left="50" Name="rect1" Fill="#4682b4" Width="100" Height="100"/>
196 <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
197 <Button Name="Button1" Click="clipRect" Margin="0,5,5,5">Canvas.ClipToBounds="True"</Button><Button Name="Button2" Margin="0,5,5,5" Click="unclipRect">Canvas.ClipToBounds="False"</Button>
200 <Grid.RowDefinitions>
203 </Grid.RowDefinitions>
204 <Grid.ColumnDefinitions>
205 <ColumnDefinition Width="Auto"/>
206 <ColumnDefinition Width="Auto"/>
207 <ColumnDefinition Width="Auto"/>
208 <ColumnDefinition Width="Auto"/>
209 <ColumnDefinition Width="Auto"/>
210 <ColumnDefinition Width="Auto"/>
211 </Grid.ColumnDefinitions>
212 <TextBlock Grid.Row="0" FontSize="14" FontWeight="Bold" Grid.ColumnSpan="6" HorizontalAlignment="Center" Margin="0,15,0,15" TextWrapping="Wrap">
213 Use the ListBoxes below to manipulate the various Width related properties of the Rectangle above.</TextBlock>
214 <TextBlock Grid.Row="1" Grid.Column="0" Margin="10,0,0,0" TextWrapping="Wrap">Set the Rectangle Width:</TextBlock>
215 <ListBox Grid.Column="1" Grid.Row="1" Margin="10,0,0,0" Width="50" Height="50" SelectionChanged="changeWidth">
216 <ListBoxItem>25</ListBoxItem>
217 <ListBoxItem>50</ListBoxItem>
218 <ListBoxItem>75</ListBoxItem>
219 <ListBoxItem>100</ListBoxItem>
220 <ListBoxItem>125</ListBoxItem>
221 <ListBoxItem>150</ListBoxItem>
222 <ListBoxItem>175</ListBoxItem>
223 <ListBoxItem>200</ListBoxItem>
224 <ListBoxItem>225</ListBoxItem>
225 <ListBoxItem>250</ListBoxItem>
228 <TextBlock Grid.Row="1" Grid.Column="2" Margin="10,0,0,0" TextWrapping="Wrap">Set the Rectangle MinWidth:</TextBlock>
229 <ListBox Grid.Column="3" Grid.Row="1" Margin="10,0,0,0" Width="50" Height="50" SelectionChanged="changeMinWidth">
230 <ListBoxItem>25</ListBoxItem>
231 <ListBoxItem>50</ListBoxItem>
232 <ListBoxItem>75</ListBoxItem>
233 <ListBoxItem>100</ListBoxItem>
234 <ListBoxItem>125</ListBoxItem>
235 <ListBoxItem>150</ListBoxItem>
236 <ListBoxItem>175</ListBoxItem>
237 <ListBoxItem>200</ListBoxItem>
238 <ListBoxItem>225</ListBoxItem>
239 <ListBoxItem>250</ListBoxItem>
242 <TextBlock Grid.Row="1" Grid.Column="4" Margin="10,0,0,0" TextWrapping="Wrap">Set the Rectangle MaxWidth:</TextBlock>
243 <ListBox Grid.Column="5" Grid.Row="1" Margin="10,0,0,0" Width="50" Height="50" SelectionChanged="changeMaxWidth">
244 <ListBoxItem>25</ListBoxItem>
245 <ListBoxItem>50</ListBoxItem>
246 <ListBoxItem>75</ListBoxItem>
247 <ListBoxItem>100</ListBoxItem>
248 <ListBoxItem>125</ListBoxItem>
249 <ListBoxItem>150</ListBoxItem>
250 <ListBoxItem>175</ListBoxItem>
251 <ListBoxItem>200</ListBoxItem>
252 <ListBoxItem>225</ListBoxItem>
253 <ListBoxItem>250</ListBoxItem>
257 <TextBlock Name="txt1"/>
258 <TextBlock Name="txt2"/>
259 <TextBlock Name="txt3"/>
260 <TextBlock Name="txt4"/>
261 <TextBlock Name="txt5"/>