added SSCLI 1.0
[windows-sources.git] / sdk / samples / WPFSamples / SamplesGallery / csharp / samps / actualwidth_samp.xaml
blob5ec4f055b8dc38260a813f9666123c4d31ffa05e
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"
5       Loaded="checkLang">
7     <TabControl MinHeight="500" MaxHeight="700" MinWidth="400">
8         <TabItem Style="{StaticResource TabStyle}" Header="Width Properties Sample" IsSelected="true">
9             <StackPanel>
10             <TextBlock Style="{StaticResource HeaderStyle}">Width Properties Sample</TextBlock>
11     
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>
14             </StackPanel>
15         </TabItem>
16         
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">
23 &lt;Window  
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     &lt;Border BorderBrush="Black" BorderThickness="2" Background="White">
29         &lt;StackPanel Margin="10">
30         
31                 &lt;TextBlock FontSize="20" DockPanel.Dock="Top">Width Properties Sample&lt;/TextBlock>
32         &lt;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.&lt;/TextBlock>
33         &lt;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:&lt;/TextBlock>
34             &lt;Canvas Height="200" MinWidth="200" Background="#b0c4de" VerticalAlignment="Top"  HorizontalAlignment="Center" Name="myCanvas">
35                 &lt;Rectangle HorizontalAlignment="Center" Canvas.Top="50" Canvas.Left="50"  Name="rect1" Fill="#4682b4" Width="100" Height="100"/>
36             &lt;/Canvas>
37         &lt;StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
38             &lt;Button Name="Button1" Click="clipRect" Margin="0,5,5,5">Canvas.ClipToBounds="True"&lt;/Button>&lt;Button Name="Button2" Margin="0,5,5,5" Click="unclipRect">Canvas.ClipToBounds="False"&lt;/Button>
39         &lt;/StackPanel>
40             &lt;Grid>
41             &lt;RowDefinition/>
42             &lt;RowDefinition/>
43             &lt;ColumnDefinition Width="Auto"/>
44             &lt;ColumnDefinition Width="Auto"/>
45             &lt;ColumnDefinition Width="Auto"/>
46             &lt;ColumnDefinition Width="Auto"/>
47             &lt;ColumnDefinition Width="Auto"/>
48             &lt;ColumnDefinition Width="Auto"/>
49     &lt;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.&lt;/TextBlock>
51     &lt;TextBlock Grid.Row="1" Grid.Column="0" Margin="10,0,0,0" TextWrapping="Wrap">Set the Rectangle Width:&lt;/TextBlock>
52     &lt;ListBox Grid.Column="1" Grid.Row="1" Margin="10,0,0,0" Width="50" Height="50" SelectionChanged="changeWidth">
53       &lt;ListBoxItem>25&lt;/ListBoxItem>
54       &lt;ListBoxItem>50&lt;/ListBoxItem>
55       &lt;ListBoxItem>75&lt;/ListBoxItem>
56       &lt;ListBoxItem>100&lt;/ListBoxItem>
57       &lt;ListBoxItem>125&lt;/ListBoxItem>
58       &lt;ListBoxItem>150&lt;/ListBoxItem>
59       &lt;ListBoxItem>175&lt;/ListBoxItem>
60       &lt;ListBoxItem>200&lt;/ListBoxItem>
61       &lt;ListBoxItem>225&lt;/ListBoxItem>
62       &lt;ListBoxItem>250&lt;/ListBoxItem>
63     &lt;/ListBox>
65         &lt;TextBlock Grid.Row="1" Grid.Column="2" Margin="10,0,0,0" TextWrapping="Wrap">Set the Rectangle MinWidth:&lt;/TextBlock>
66     &lt;ListBox Grid.Column="3" Grid.Row="1" Margin="10,0,0,0" Width="50" Height="50" SelectionChanged="changeMinWidth">
67       &lt;ListBoxItem>25&lt;/ListBoxItem>
68       &lt;ListBoxItem>50&lt;/ListBoxItem>
69       &lt;ListBoxItem>75&lt;/ListBoxItem>
70       &lt;ListBoxItem>100&lt;/ListBoxItem>
71       &lt;ListBoxItem>125&lt;/ListBoxItem>
72       &lt;ListBoxItem>150&lt;/ListBoxItem>
73       &lt;ListBoxItem>175&lt;/ListBoxItem>
74       &lt;ListBoxItem>200&lt;/ListBoxItem>
75       &lt;ListBoxItem>225&lt;/ListBoxItem>
76       &lt;ListBoxItem>250&lt;/ListBoxItem>
77   &lt;/ListBox>      
78      
79     &lt;TextBlock Grid.Row="1" Grid.Column="4" Margin="10,0,0,0" TextWrapping="Wrap">Set the Rectangle MaxWidth:&lt;/TextBlock>
80     &lt;ListBox Grid.Column="5" Grid.Row="1" Margin="10,0,0,0" Width="50" Height="50" SelectionChanged="changeMaxWidth">
81       &lt;ListBoxItem>25&lt;/ListBoxItem>
82       &lt;ListBoxItem>50&lt;/ListBoxItem>
83       &lt;ListBoxItem>75&lt;/ListBoxItem>
84       &lt;ListBoxItem>100&lt;/ListBoxItem>
85       &lt;ListBoxItem>125&lt;/ListBoxItem>
86       &lt;ListBoxItem>150&lt;/ListBoxItem>
87       &lt;ListBoxItem>175&lt;/ListBoxItem>
88       &lt;ListBoxItem>200&lt;/ListBoxItem>
89       &lt;ListBoxItem>225&lt;/ListBoxItem>
90       &lt;ListBoxItem>250&lt;/ListBoxItem>  
91     &lt;/ListBox>
92         &lt;/Grid>
94             &lt;TextBlock Name="txt1"/>
95         &lt;TextBlock Name="txt2"/>
96         &lt;TextBlock Name="txt3"/>
97         &lt;TextBlock Name="txt4"/>
98         &lt;TextBlock Name="txt5"/>
99         &lt;/StackPanel>
100         &lt;/Border>    
101 &lt;/Window>
104             </TextBox>    
105                   </ScrollViewer>
106                   
107                 </TabItem>
108                 <TabItem Style="{StaticResource TabStyle2}" Header="C#">
109                     <ScrollViewer>
110                   <TextBox Style="{StaticResource CodeSnippetParagraph}" xml:space="preserve">
111 using System;
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
120     {
121         public void changeWidth(object sender, RoutedEventArgs args)
122         {
123             ListBoxItem li = ((sender as ListBox).SelectedItem as ListBoxItem);
124             Double sz1 = Double.Parse(li.Content.ToString());
125             rect1.Width = sz1;
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;
131         }
132         public void changeMinWidth(object sender, RoutedEventArgs args)
133         {
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;
142         }
143         public void changeMaxWidth(object sender, RoutedEventArgs args)
144         {
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;
153         }
155         public void clipRect(object sender, RoutedEventArgs args)
156         {
157             myCanvas.ClipToBounds = true;
158             txt5.Text = "Canvas.ClipToBounds is set to " + myCanvas.ClipToBounds;
159         }
160         public void unclipRect(object sender, RoutedEventArgs args)
161         {
162             myCanvas.ClipToBounds = false;
163             txt5.Text = "Canvas.ClipToBounds is set to " + myCanvas.ClipToBounds;
164         }
165     }
166 }                
167                 
168             </TextBox>    
169                   </ScrollViewer>
170                 </TabItem>
171             </TabControl>  
172         </TabItem>
173         
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>
178             </TabControl>
179          </TabItem> 
180         <TabItem Name="csharp" Style="{StaticResource TabStyle}" Header="C#"></TabItem>
181     
182         <TabItem Name="vb" Style="{StaticResource TabStyle}" Header="Visual Basic.NET"></TabItem>
184         <TabItem Name="managedcpp" Style="{StaticResource TabStyle}" Header="Managed C++"></TabItem>
185     
186         <TabItem Style="{StaticResource TabStyle}" Header="Preview Sample">
187     <Border BorderBrush="Black" BorderThickness="2" Background="White">
188         <StackPanel Margin="10">
189         
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"/>
195             </Canvas>
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>
198         </StackPanel>
199             <Grid>
200               <Grid.RowDefinitions>
201             <RowDefinition/>
202             <RowDefinition/>
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>
226     </ListBox>
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>
240   </ListBox>      
241      
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>  
254     </ListBox>
255         </Grid>
257             <TextBlock Name="txt1"/>
258         <TextBlock Name="txt2"/>
259         <TextBlock Name="txt3"/>
260         <TextBlock Name="txt4"/>
261         <TextBlock Name="txt5"/>
262         </StackPanel>
263         </Border>
265         </TabItem>
266             
267     </TabControl>
269 </Page>