How to add multiple user controls to Accordion in xaml
I'm using a Silverlight 4 page with an Accordion to which I'm trying to insert 2 user controls to each Accordion item.
<toolkit:Accordion Name="accordion1">
<toolkit:AccordionItem Content="item 1" Header="A">
<local:AddRemoveControl x:Name="AddRemoveAgents" Margin="开发者_如何学编程470,90,0,0"> </local:AddRemoveControl>
</toolkit:AccordionItem>
<toolkit:AccordionItem Content="item 2" Header="B - long header">
<local:DatesFilter x:Name="DatesFilter" Margin="475,200,0,0" Canvas.Top="76"> </local:DatesFilter>
</toolkit:AccordionItem>
</toolkit:Accordion>
I'm getting the following error message: "The property content is set more than once"
How can I proceed?
Thank you!
You can only have one content item in an accordion.
What you will need to do is wrap your controls in a StackPanel:
<toolkit:Accordion Name="accordion1">
<toolkit:AccordionItem Content="item 1" Header="A">
<StackPanel>
<local:AddRemoveControl x:Name="AddRemoveAgents" Margin="470,90,0,0"></local:AddRemoveControl>
<local:DatesFilter x:Name="DatesFilter" Margin="475,200,0,0" Canvas.Top="76"> </local:DatesFilter>
</StackPanel>
</toolkit:AccordionItem>
</toolkit:Accordion>
Here is my updated code:
<toolkit:Accordion Canvas.Left="480" Canvas.Top="104" Height="100" Name="accordion1" Width="300">
<toolkit:AccordionItem Content="item 1" Header="A">
<StackPanel>
<local:AddRemoveControl x:Name="AddRemoveAgents" Margin="470,90,0,0"></local:AddRemoveControl>
</StackPanel>
</toolkit:AccordionItem>
<toolkit:AccordionItem Content="item 2" Header="B - long header">
<StackPanel>
<local:DatesFilter x:Name="DatesFilter" Margin="475,200,0,0" Canvas.Top="76"></local:DatesFilter>
</StackPanel>
</toolkit:AccordionItem>
</toolkit:Accordion>
You are defining the content twice. Try removing the content tags from the AccordionItem like this:
<toolkit:Accordion Canvas.Left="480" Canvas.Top="104" Height="100" Name="accordion1" Width="300">
<toolkit:AccordionItem Header="A">
<StackPanel>
<local:AddRemoveControl x:Name="AddRemoveAgents" Margin="470,90,0,0"></local:AddRemoveControl>
</StackPanel>
</toolkit:AccordionItem>
<toolkit:AccordionItem Header="B - long header">
<StackPanel>
<local:DatesFilter x:Name="DatesFilter" Margin="475,200,0,0" Canvas.Top="76"></local:DatesFilter>
</StackPanel>
</toolkit:AccordionItem>
</toolkit:Accordion>
Also, the way you have it currently you will end up with two Accodion items with one control in each. To get both the controls in the same item you need to put the second control in the first stackpanel.
<toolkit:Accordion Canvas.Left="480" Canvas.Top="104" Height="100" Name="accordion1" Width="300">
<toolkit:AccordionItem Header="A">
<StackPanel>
<local:AddRemoveControl x:Name="AddRemoveAgents" Margin="470,90,0,0">
</local:AddRemoveControl>
<local:DatesFilter x:Name="DatesFilter" Margin="475,200,0,0" Canvas.Top="76">
</local:DatesFilter>
</StackPanel>
</toolkit:AccordionItem>
精彩评论