2011-03-16 54 views
4

我正在使用帶有Accordion的Silverlight 4頁面,我試圖向每個Accordion項目插入2個用戶控件。如何將多個用戶控件添加到xaml中的手風琴

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

我收到以下錯誤信息:「該物業含量更比一次」

我如何進行?

謝謝!

+0

你能也許組中的堆疊面板控件,並設置堆棧面板作爲手風琴內容? – BigPete 2011-03-16 11:34:17

回答

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

謝謝,但我一直在收到相同的錯誤 – 2011-03-16 11:36:57

+0

@dana - 你可以編輯你的問題更新的代碼 - http://stackoverflow.com/posts/5324581/edit - 不要取代原來的代碼。 – ChrisF 2011-03-16 11:38:42

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

+0

您是否找到了解決方法? – BigPete 2011-03-19 02:42:13

+0

非常感謝您的幫助。我嘗試了你的建議代碼。手風琴出現了,但我擔心我的控件不會顯示在手風琴項目中。這可能是什麼原因? – 2011-03-21 06:00:13

+0

這可能是利潤率問題。嘗試設置相對於堆疊面板而不是畫布的邊距。 – BigPete 2011-03-22 02:17:13

相關問題