- Mastering Visual Studio 2017
- Kunal Chowdhury
- 59字
- 2021-07-15 17:26:42
Collection syntax
Sometimes it's required to define a collection of elements in the XAML. This is done using the Collection syntax to make it more readable. For example, a StackPanel can have multiple elements defined inside the Children property :
<StackPanel> <StackPanel.Children> <Button Content="1" /> <Button Content="2" /> </StackPanel.Children> </StackPanel>
The preceding example can also be written as follows, where the parser knows how to create and assign it:
<StackPanel> <Button Content="1" /> <Button Content="2" /> </StackPanel>