2012-06-03 40 views
1

我有字符串數組。它看起來是這樣的:如何在全景物品中動態創建按鈕?

enter image description here

我有一個空的全景:

<controls:Panorama x:Name="MainPanorama"> 

</controls:Panorama> 

我想動態,用我的陣列,創建全景頁面全景物品, 它應該是這樣的:

<controls:Panorama x:Name="MainPanorama"> 
    <controls:PanoramaItem Header="first"> 
     <ScrollViewer> 
      <StackPanel> 
       <Button Name="button1" content="create"/> 
       <Button Name="button2" content="save"/> 
       <Button Name="button3" content="open"/> 
      </StackPanel> 
     </ScrollViewer> 
    </controls:PanoramaItem> 
    <controls:PanoramaItem Header="second"> 
     <ScrollViewer> 
      <StackPanel> 
       <Button Name="button4" content="save as"/> 
       <Button Name="button5" content="import"/> 
      </StackPanel> 
     </ScrollViewer> 
    </controls:PanoramaItem> 
</controls:Panorama> 

所以,問題是:如何在全景項目中動態創建按鈕?按鈕必須有不同的名稱。我在這裏展示的數組不是實際的數組。在我的工作中,我有另一個更大的,但我認爲這足以理解這個問題。

回答

0

您可以使用項目控件來實現此目標(ListBox或等):將字符串數組綁定爲項目源,並將按鈕設置爲項目模板。請閱讀有關Silverlight中控件和綁定的更多信息。