added samples
[windows-sources.git] / sdk / samples / WPFSamples / SamplesGallery / csharp / samps / listboxstyle_samp.xaml
blob5a578f90545bac6bc42b843f52156b622453bc4c
1 <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
2       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3       Title="Sample Title"
4       x:Class="ListBoxStyle.Page1"
5       Loaded="checkLang">
6 <TabControl MinHeight="500" MaxHeight="700" MinWidth="400">
7                 <TabItem Style="{StaticResource TabStyle}" Header="List Box Sample" IsSelected="true">
8                     <StackPanel>
9                         <TextBlock Style="{StaticResource HeaderStyle}">List Box Styles</TextBlock>
11                         <TextBlock Style="{StaticResource mainContentStyle}">This example demonstrates ListBox controls with styles applied.</TextBlock>
13                     </StackPanel>
14                 </TabItem>
16                 <TabItem Name="xaml" Style="{StaticResource TabStyle}" Header="XAML">
18                     
20                 </TabItem>
21          <TabItem Name="xamlcsharp" Style="{StaticResource TabStyle}" Header="XAML + C#">
22             <TabControl TabStripPlacement="Right">
23                 <TabItem Name="xcsharpCheck" Style="{StaticResource TabStyle2}" Header="XAML">
24                     <ScrollViewer HorizontalScrollBarVisibility="Visible">
25                     <TextBox Style="{StaticResource CodeSnippetParagraph}" xml:space="preserve">
26                       
27 &lt;Canvas>
28   &lt;Canvas.Resources>
29     &lt;Style x:Key="Simple" TargetType="{x:Type ListBox}">
30       &lt;Setter Property = "SelectionMode" Value="Single"/>
31       &lt;Setter Property = "Background" Value="Red"/>
32     &lt;/Style>
34     &lt;Style x:Key="SimpleListBoxItem" TargetType="{x:Type ListBoxItem}">
35       &lt;Setter Property = "FontSize" Value="14"/>
36       &lt;Setter Property = "Background" Value="Pink"/>
37       &lt;Setter Property = "Foreground" Value="Purple"/>
38     &lt;/Style>
40     &lt;Style x:Key="Triggers" TargetType="{x:Type ListBoxItem}">
41       &lt;Style.Triggers>
42         &lt;Trigger Property="ListBoxItem.IsMouseOver" Value="true">
43           &lt;Setter Property = "Foreground" Value="Red"/>
44           &lt;Setter Property = "Background" Value="LightBlue"/>
45         &lt;/Trigger>
46       &lt;/Style.Triggers>
47     &lt;/Style>
48   &lt;/Canvas.Resources>
51   &lt;Grid Name="grid" ShowGridLines ="false" Background ="White" >
52     &lt;Grid.ColumnDefinitions>
53     &lt;ColumnDefinition Width="300"/>
54     &lt;ColumnDefinition Width="250"/>
55     &lt;/Grid.ColumnDefinitions>
56     &lt;Grid.RowDefinitions>
57     &lt;RowDefinition/>
58     &lt;RowDefinition/>
59     &lt;RowDefinition/>
60     &lt;RowDefinition/>
61     &lt;RowDefinition/>
62     &lt;RowDefinition/>
63     &lt;RowDefinition/>
64     &lt;RowDefinition/>
65     &lt;RowDefinition/>
66     &lt;RowDefinition/>
67     &lt;RowDefinition/>
68     &lt;RowDefinition/>
69     &lt;RowDefinition/>
70     &lt;/Grid.RowDefinitions>
71     &lt;TextBlock Margin="10, 10, 3, 3" Grid.Column="0" Grid.Row="0" FontSize="24">List Boxes&lt;/TextBlock>
72     &lt;TextBlock Margin="10, 10, 3, 3" Grid.Column="0" Grid.Row="1" FontSize="14" Grid.ColumnSpan="2">The following list box examples are created using styles:&lt;/TextBlock>
74     &lt;DockPanel Margin="10, 10, 3, 3" Grid.Column="0" Grid.Row="2">
75       &lt;TextBox Name="tb" Width="140" Height="30">&lt;/TextBox>
77       &lt;ListBox Style="{StaticResource Simple}" Width="100" Height="55" SelectionChanged="PrintText">
79         &lt;ListBoxItem>Item 1&lt;/ListBoxItem>
80         &lt;ListBoxItem>Item 2&lt;/ListBoxItem>
81         &lt;ListBoxItem>Item 3&lt;/ListBoxItem>
82         &lt;ListBoxItem>Item 4&lt;/ListBoxItem>
83         &lt;ListBoxItem>Item 5&lt;/ListBoxItem>
84         &lt;ListBoxItem>Item 6&lt;/ListBoxItem>
85         &lt;ListBoxItem>Item 7&lt;/ListBoxItem>
86         &lt;ListBoxItem>Item 8&lt;/ListBoxItem>
87         &lt;ListBoxItem>Item 9&lt;/ListBoxItem>
88         &lt;ListBoxItem>Item 10&lt;/ListBoxItem>
89       &lt;/ListBox>
90     &lt;/DockPanel>
91     &lt;TextBlock Margin="10, 10, 3, 3" Grid.Column="1" Grid.Row="2" FontSize="12" VerticalAlignment="Center" TextWrapping="Wrap">Style sets the list box to only allow one item to be selected at a time and changes the background color.&lt;/TextBlock>
93     &lt;DockPanel Margin="10, 10, 3, 3" Grid.Column="0" Grid.Row="3">
94       &lt;ListBox Width="260" Height="55" HorizontalAlignment="Left">
96         &lt;ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 1&lt;/ListBoxItem>
97         &lt;ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 2&lt;/ListBoxItem>
98         &lt;ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 3&lt;/ListBoxItem>
99         &lt;ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 4&lt;/ListBoxItem>
100         &lt;ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 5&lt;/ListBoxItem>
101         &lt;ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 6&lt;/ListBoxItem>
102         &lt;ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 7&lt;/ListBoxItem>
103         &lt;ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 8&lt;/ListBoxItem>
104         &lt;ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 9&lt;/ListBoxItem>
105         &lt;ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 10&lt;/ListBoxItem>
106       &lt;/ListBox>
107     &lt;/DockPanel>
108     &lt;TextBlock Margin="10, 10, 3, 3" Grid.Column="1" Grid.Row="3" FontSize="12" VerticalAlignment="Center" TextWrapping="Wrap">Style changes the background, foreground, and font size of the list box items.&lt;/TextBlock>
110     &lt;DockPanel Margin="10, 10, 3, 3" Grid.Column="0" Grid.Row="4">
111       &lt;ListBox Width="260" Height="55" HorizontalAlignment="Left">
113         &lt;ListBoxItem Style="{StaticResource Triggers}">Item 1&lt;/ListBoxItem>
114         &lt;ListBoxItem Style="{StaticResource Triggers}">Item 2&lt;/ListBoxItem>
115         &lt;ListBoxItem Style="{StaticResource Triggers}">Item 3&lt;/ListBoxItem>
116         &lt;ListBoxItem Style="{StaticResource Triggers}">Item 4&lt;/ListBoxItem>
117         &lt;ListBoxItem Style="{StaticResource Triggers}">Item 5&lt;/ListBoxItem>
118         &lt;ListBoxItem Style="{StaticResource Triggers}">Item 6&lt;/ListBoxItem>
119         &lt;ListBoxItem Style="{StaticResource Triggers}">Item 7&lt;/ListBoxItem>
120         &lt;ListBoxItem Style="{StaticResource Triggers}">Item 8&lt;/ListBoxItem>
121         &lt;ListBoxItem Style="{StaticResource Triggers}">Item 9&lt;/ListBoxItem>
122         &lt;ListBoxItem Style="{StaticResource Triggers}">Item 10&lt;/ListBoxItem>
123       &lt;/ListBox>
124     &lt;/DockPanel>
125     &lt;TextBlock Margin="10, 10, 3, 3" Grid.Column="1" Grid.Row="4" FontSize="12" VerticalAlignment="Center" TextWrapping="Wrap">Style changes the background and foreground colors of the list box items in response to a mouse over event.&lt;/TextBlock>
127   &lt;/Grid>
128 &lt;/Canvas>
129              
130             </TextBox>
131                         </ScrollViewer>
132                 </TabItem>
133                 <TabItem Style="{StaticResource TabStyle2}" Header="C#">
134                     <ScrollViewer HorizontalScrollBarVisibility="Visible">
135                 <TextBox Style="{StaticResource CodeSnippetParagraph}" xml:space="preserve">
137 using System;
138 using System.Windows;
139 using System.Windows.Controls;
140 using System.Windows.Documents;
141 using System.Windows.Navigation;
142 using System.Windows.Shapes;
143 using System.Windows.Data;
145 namespace ListBoxEvent_wcp
147         /// Interaction logic for Pane1.xaml
149         public partial class Pane1 : Canvas
150         {
151                 void PrintText(object sender, RoutedEventArgs args)
152                 {
153                         ListBoxItem li = ((sender as ListBox).SelectedItem as ListBoxItem);
155                         tb.Text = "   You selected " + li.Content.ToString() + ".";
156                 }
157         }
159 </TextBox>
160                         </ScrollViewer>
161                 </TabItem>
162             </TabControl>  
163         </TabItem>
164         
165          <TabItem Name="xamlvb" Style="{StaticResource TabStyle}" Header="XAML + Visual Basic.NET">
166             <TabControl TabStripPlacement="Right">
167                 <TabItem Name="xvbCheck" Style="{StaticResource TabStyle2}" Header="XAML"></TabItem>
168                 <TabItem Style="{StaticResource TabStyle2}" Header="VB.NET"></TabItem>
169             </TabControl>
170          </TabItem> 
171     
172         <TabItem Name="csharp" Style="{StaticResource TabStyle}" Header="C#"></TabItem>
173     
174         <TabItem Name="vb" Style="{StaticResource TabStyle}" Header="Visual Basic.NET"></TabItem>
176         <TabItem Name="managedcpp" Style="{StaticResource TabStyle}" Header="Managed C++"></TabItem>
177     
178         <TabItem Style="{StaticResource TabStyle}" Header="Preview Sample">
180                     
181   
182                     <Canvas>
183                         <Canvas.Resources>
184                             <Style x:Key="Simple" TargetType="{x:Type ListBox}">
185                                 <Setter Property = "SelectionMode" Value="Single"/>
186                                 <Setter Property = "Background" Value="Red"/>
187                             </Style>
189                             <Style x:Key="SimpleListBoxItem" TargetType="{x:Type ListBoxItem}">
190                                 <Setter Property = "FontSize" Value="14"/>
191                                 <Setter Property = "Background" Value="Pink"/>
192                                 <Setter Property = "Foreground" Value="Purple"/>
193                             </Style>
195                             <Style x:Key="Triggers" TargetType="{x:Type ListBoxItem}">
196                                 <Style.Triggers>
197                                     <Trigger Property="ListBoxItem.IsMouseOver" Value="true">
198                                         <Setter Property = "Foreground" Value="Red"/>
199                                         <Setter Property = "Background" Value="LightBlue"/>
200                                     </Trigger>
201                                 </Style.Triggers>
202                             </Style>
203                         </Canvas.Resources>
206                         <Grid Name="grid" ShowGridLines ="false" Background ="White" >
207                           <Grid.ColumnDefinitions>
208                             <ColumnDefinition Width="300"/>
209                             <ColumnDefinition Width="250"/>
210                           </Grid.ColumnDefinitions>
211                           <Grid.RowDefinitions>
212                             <RowDefinition/>
213                             <RowDefinition/>
214                             <RowDefinition/>
215                             <RowDefinition/>
216                             <RowDefinition/>
217                             <RowDefinition/>
218                             <RowDefinition/>
219                             <RowDefinition/>
220                             <RowDefinition/>
221                             <RowDefinition/>
222                             <RowDefinition/>
223                             <RowDefinition/>
224                             <RowDefinition/>
225                           </Grid.RowDefinitions>
226                             <TextBlock Margin="10, 10, 3, 3" Grid.Column="0" Grid.Row="0" FontSize="24">List Boxes</TextBlock>
227                             <TextBlock Margin="10, 10, 3, 3" Grid.Column="0" Grid.Row="1" FontSize="14" Grid.ColumnSpan="2">The following list box examples are created using styles:</TextBlock>
228                             <DockPanel Margin="10, 10, 3, 3" Grid.Column="0" Grid.Row="2">
230                                 <TextBox Name="tb" Width="140" Height="30"></TextBox>
232                                 <ListBox Style="{StaticResource Simple}" Width="100" Height="55" SelectionChanged="PrintText">
234                                     <ListBoxItem>Item 1</ListBoxItem>
235                                     <ListBoxItem>Item 2</ListBoxItem>
236                                     <ListBoxItem>Item 3</ListBoxItem>
237                                     <ListBoxItem>Item 4</ListBoxItem>
238                                     <ListBoxItem>Item 5</ListBoxItem>
239                                     <ListBoxItem>Item 6</ListBoxItem>
240                                     <ListBoxItem>Item 7</ListBoxItem>
241                                     <ListBoxItem>Item 8</ListBoxItem>
242                                     <ListBoxItem>Item 9</ListBoxItem>
243                                     <ListBoxItem>Item 10</ListBoxItem>
244                                 </ListBox>
245                             </DockPanel>
246                             <TextBlock Margin="10, 10, 3, 3" Grid.Column="1" Grid.Row="2" FontSize="12" VerticalAlignment="Center" TextWrapping="Wrap">Style sets the list box to only allow one item to be selected at a time and changes the background color.</TextBlock>
248                             <DockPanel Margin="10, 10, 3, 3" Grid.Column="0" Grid.Row="3">
249                                 <ListBox Width="260" Height="55" HorizontalAlignment="Left">
251                                     <ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 1</ListBoxItem>
252                                     <ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 2</ListBoxItem>
253                                     <ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 3</ListBoxItem>
254                                     <ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 4</ListBoxItem>
255                                     <ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 5</ListBoxItem>
256                                     <ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 6</ListBoxItem>
257                                     <ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 7</ListBoxItem>
258                                     <ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 8</ListBoxItem>
259                                     <ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 9</ListBoxItem>
260                                     <ListBoxItem Style="{StaticResource SimpleListBoxItem}">Item 10</ListBoxItem>
261                                 </ListBox>
262                             </DockPanel>
263                             <TextBlock Margin="10, 10, 3, 3" Grid.Column="1" Grid.Row="3" FontSize="12" VerticalAlignment="Center" TextWrapping="Wrap">Style changes the background, foreground, and font size of the list box items.</TextBlock>
265                             <DockPanel Margin="10, 10, 3, 3" Grid.Column="0" Grid.Row="4">
266                                 <ListBox Width="260" Height="55" HorizontalAlignment="Left">
268                                     <ListBoxItem Style="{StaticResource Triggers}">Item 1</ListBoxItem>
269                                     <ListBoxItem Style="{StaticResource Triggers}">Item 2</ListBoxItem>
270                                     <ListBoxItem Style="{StaticResource Triggers}">Item 3</ListBoxItem>
271                                     <ListBoxItem Style="{StaticResource Triggers}">Item 4</ListBoxItem>
272                                     <ListBoxItem Style="{StaticResource Triggers}">Item 5</ListBoxItem>
273                                     <ListBoxItem Style="{StaticResource Triggers}">Item 6</ListBoxItem>
274                                     <ListBoxItem Style="{StaticResource Triggers}">Item 7</ListBoxItem>
275                                     <ListBoxItem Style="{StaticResource Triggers}">Item 8</ListBoxItem>
276                                     <ListBoxItem Style="{StaticResource Triggers}">Item 9</ListBoxItem>
277                                     <ListBoxItem Style="{StaticResource Triggers}">Item 10</ListBoxItem>
278                                 </ListBox>
279                             </DockPanel>
280                             <TextBlock Margin="10, 10, 3, 3" Grid.Column="1" Grid.Row="4" FontSize="12" VerticalAlignment="Center" TextWrapping="Wrap">Style changes the background and foreground colors of the list box items in response to a mouse over event.</TextBlock>
282                         </Grid>
283                     </Canvas>
284                 </TabItem>
285             </TabControl>
286 </Page>