如何在xaml中向Accordion添加多个用户控件

时间:2011-03-16 11:27:01

标签: silverlight xaml accordion

我正在使用带有Accordion的Silverlight 4页面,我正在尝试为每个Accordion项目插入2个用户控件。

<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>

我收到以下错误消息:“属性内容设置多次”

我该怎么办?

谢谢!

3 个答案:

答案 0 :(得分:2)

手风琴中只能有一个内容项。

您需要做的是将控件包装在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>

答案 1 :(得分:0)

这是我更新的代码:

<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>

答案 2 :(得分:0)

您要定义内容两次。尝试从AccordionItem中删除内容标记,如下所示:

<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>

此外,你现在拥有它的方式最终会得到两个Accodion项目,每个项目都有一个控件。要在同一项目中获取两个控件,您需要将第二个控件放在第一个堆栈面板中。

<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>