1 <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3 Title="Composite Collections"
4 x:Class="CompositeCollections.Page1"
6 <TabControl MinHeight="500" MaxHeight="700" MinWidth="400">
7 <TabItem Style="{StaticResource TabStyle}" Header="Composite Collections Sample" IsSelected="true">
9 <TextBlock Style="{StaticResource HeaderStyle}">Composite Collections Sample</TextBlock>
11 <TextBlock Style="{StaticResource mainContentStyle}">This sample shows how to implement data binding using collections composed of mixed types of data.</TextBlock>
16 <TabItem Name="xaml" Style="{StaticResource TabStyle}" Header="XAML">
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">
26 <TextBox Style="{StaticResource CodeSnippetParagraph}" xml:space="preserve">
27 <Window Background="Cornsilk"
28 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
29 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
30 xmlns:c="clr-namespace:CompositeCollections"
31 x:Class="SDKSample.CompositeCollections"
32 Title="CompositeCollections"
37 <c:GreekGods x:Key="GreekGodsData"/>
39 <XmlDataProvider x:Key="GreekHeroesData" XPath="GreekHeroes/Hero">
40 <GreekHeroes xmlns="">
41 <Hero Name="Jason" />
42 <Hero Name="Hercules" />
43 <Hero Name="Bellerophon" />
44 <Hero Name="Theseus" />
45 <Hero Name="Odysseus" />
46 <Hero Name="Perseus" />
50 <DataTemplate DataType="{x:Type c:GreekGod}">
51 <TextBlock Text="{Binding Path=Name}" Foreground="Gold"/>
53 <DataTemplate DataType="Hero">
54 <TextBlock Text="{Binding XPath=@Name}" Foreground="Cyan"/>
56 </Window.Resources>
59 <TextBlock FontSize="18" FontWeight="Bold" Margin="10"
60 HorizontalAlignment="Center">Composite Collections Sample</TextBlock>
61 <ListBox Name="lbGodsAndHeroes" Height="300" Width="200" Background="White">
62 <ListBox.ItemsSource>
63 <CompositeCollection>
64 <CollectionContainer Collection="{Binding Source={StaticResource GreekGodsData}}" />
65 <CollectionContainer Collection="{Binding Source={StaticResource GreekHeroesData}}" />
66 <ListBoxItem Foreground="Red">Other Listbox Item 1</ListBoxItem>
67 <ListBoxItem Foreground="Red">Other Listbox Item 2</ListBoxItem>
68 </CompositeCollection>
69 </ListBox.ItemsSource>
79 <TabItem Style="{StaticResource TabStyle2}" Header="C#">
80 <ScrollViewer HorizontalScrollBarVisibility="Visible">
82 <TextBox Style="{StaticResource CodeSnippetParagraph}" xml:space="preserve">
84 using System.ComponentModel;
86 using System.Windows.Controls;
87 using System.Windows.Documents;
88 using System.Windows.Navigation;
89 using System.Windows.Shapes;
90 using System.Windows.Data;
94 public partial class Window1 : Window
98 InitializeComponent();
102 public class GreekGod
104 private string _name;
119 public GreekGod(string name)
125 public class GreekGods : ObservableCollection<GreekGod>
129 Add(new GreekGod("Aphrodite"));
130 Add(new GreekGod("Apollo"));
131 Add(new GreekGod("Ares"));
132 Add(new GreekGod("Artemis"));
133 Add(new GreekGod("Athena"));
134 Add(new GreekGod("Demeter"));
135 Add(new GreekGod("Dionysus"));
136 Add(new GreekGod("Hephaestus"));
137 Add(new GreekGod("Hera"));
138 Add(new GreekGod("Hermes"));
139 Add(new GreekGod("Poseidon"));
140 Add(new GreekGod("Zeus"));
152 <TabItem Name="xamlvb" Style="{StaticResource TabStyle}" Header="XAML + Visual Basic.NET">
153 <TabControl TabStripPlacement="Right">
154 <TabItem Name="xvbCheck" Style="{StaticResource TabStyle2}" Header="XAML"></TabItem>
155 <TabItem Style="{StaticResource TabStyle2}" Header="VB.NET"></TabItem>
159 <TabItem Name="csharp" Style="{StaticResource TabStyle}" Header="C#"></TabItem>
161 <TabItem Name="vb" Style="{StaticResource TabStyle}" Header="Visual Basic.NET"></TabItem>
163 <TabItem Name="managedcpp" Style="{StaticResource TabStyle}" Header="Managed C++"></TabItem>
165 <TabItem Style="{StaticResource TabStyle}" Header="Preview Sample">
167 <Canvas Background="Cornsilk"
168 xmlns:c="clr-namespace:CompositeCollections"
173 <c:GreekGods x:Key="GreekGodsData"/>
175 <XmlDataProvider x:Key="GreekHeroesData" XPath="GreekHeroes/Hero">
177 <GreekHeroes xmlns="">
178 <Hero Name="Jason" />
179 <Hero Name="Hercules" />
180 <Hero Name="Bellerophon" />
181 <Hero Name="Theseus" />
182 <Hero Name="Odysseus" />
183 <Hero Name="Perseus" />
188 <DataTemplate DataType="{x:Type c:GreekGod}">
189 <TextBlock Text="{Binding Path=Name}" Foreground="Gold"/>
191 <DataTemplate DataType="Hero">
192 <TextBlock Text="{Binding XPath=@Name}" Foreground="Cyan"/>
197 <TextBlock FontSize="18" FontWeight="Bold" Margin="10"
198 HorizontalAlignment="Center">Composite Collections Sample</TextBlock>
199 <ListBox Name="lbGodsAndHeroes" Height="300" Width="200" Background="White">
200 <ListBox.ItemsSource>
201 <CompositeCollection>
202 <CollectionContainer Collection="{Binding Source={StaticResource GreekGodsData}}" />
203 <CollectionContainer Collection="{Binding Source={StaticResource GreekHeroesData}}" />
204 <ListBoxItem Foreground="Red">Other Listbox Item 1</ListBoxItem>
205 <ListBoxItem Foreground="Red">Other Listbox Item 2</ListBoxItem>
206 </CompositeCollection>
207 </ListBox.ItemsSource>