silverlightxamlwindows-phonepanorama-control

How to dynamically create buttons in panorama items?


I have String array. It looks something like:

enter image description here

I have an empty panorama:

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

</controls:Panorama>

I want to dynamically, using my array, create panorama page with panorama items, it should be like:

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

So, the question is: how to dynamically create buttons in panorama items? Buttons must have different names.

p.s: The array that I show here is not the actual one. In my work I have another larger one, but I think it's enough to understand the problem.


Solution

  • You can use items controls for this goal (ListBox, or etc): bind a string array as item source and set buttons as item template. Please read more about controls and binding in Silverlight.