Collection Property for WPF UserControl
I want to create UserControl
in WPF through which I want to open a collection property. I want to change the UI UserControl
based on changes in the collection.
For example, let's say I have a rowset tied to mine UserControl
. Based on this collection, I want to create buttons on UserControl
that contain these texts as button text. Is there any way that I can figure this out?
a source to share
Yes, you can set a DataTemplate
containing button for the control ItemsControl
associated with this collection. For instance:
//For code:
items.DataContext = new List<string>
{
"Item 1",
"Item 2",
"Item 3"
};
//For XAML
<ItemsControl x:Name="items" ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
a source to share