Reputation: 33
I have created a custom circular panel inherited from panel class in WPF.
This custom control will arrange all its elements in a circular fashion. Now i want to supply the style for its child elements where ever this control is used.
As below mentioned is the usage of my control and i want to supply child items template to it from here as a property some thing like: DataTemplateToUse="{StaticResource ChildItemsTemplate}"
and this control should be intelligent enough to apply the template to all its children elemnts.
<myControl:CirclePanel InnerRadius="250" OuterRadius="300">
</myControl:CirclePanel>
ok i have used it as follows
<Grid Margin="10">
<ItemsControl Name="icTodoList">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<local:CirclePanel x:Name="CircularPanel" InnerRadius="250" OuterRadius="300" Background="Cornsilk" >
</local:CirclePanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Path=Title}" Margin="0,0,5,5"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
And dynamically from code behind i am removing the elements from my circle panel so now its throwing the error:
Cannot explicitly modify Children collection of Panel used asItemsPanel for ItemsControl. ItemsControl generates child elements for Panel
Upvotes: 0
Views: 777
Reputation: 184516
Just use an ItemsControl
with your panel as ItemsPanel
. You get all the properties for data templating and binding items.
Upvotes: 2