简体   繁体   中英

Fill panorama item dynamically in wp7

I dynamically want to add panorama items in my application. No. of item(3 to 7) is depend on the json response I am getting. Presently for testing I created 4 items in xaml and it works for me but its not dynamic. Here is my xaml.

<Grid x:Name="LayoutRoot">
    <controls:Panorama Title="my panorama" Loaded="Panorama_Loaded" Name="title1" ItemsSource="{Binding}">
        <controls:Panorama.Background>
            <ImageBrush ImageSource="/Images/Panaroma_BG.png"/>
        </controls:Panorama.Background>

        <!--Panorama item one-->
        <controls:PanoramaItem Header="item1" Name="dashboard1" HeaderTemplate="{StaticResource DashBoardName}">
            <Grid>
                <ListBox Height="512" HorizontalAlignment="Left" Margin="6,8,0,0" Name="listBox1" VerticalAlignment="Top" Width="403" Tap="listBox1_Tap">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Rectangle Height="100" Width="400" HorizontalAlignment="Left" Name="rectangle1" Stroke="Black" StrokeThickness="1" VerticalAlignment="Top"/>
                                <StackPanel Orientation="Horizontal">
                                    <Image Width="100" Height="100" Source="{Binding Image}" Stretch="Fill" HorizontalAlignment="Left" VerticalAlignment="Top" />
                                    <StackPanel Orientation="Horizontal"
                                        Height="132">
                                        <StackPanel Width="300" HorizontalAlignment="Left">
                                            <Grid>
                                                <TextBlock Text="{Binding CurrentValue}" HorizontalAlignment="Left" FontSize="25" />
                                                <Image Width="20" Height="20" Source="{Binding SubImage}" Stretch="Fill" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>
                                                <TextBlock Text="{Binding PreviousValue}" HorizontalAlignment="Right" VerticalAlignment="Top" FontSize="15" />
                                            </Grid>
                                            <StackPanel Width="290" HorizontalAlignment="Right" VerticalAlignment="Stretch" Orientation="Vertical">
                                                <TextBlock Text="{Binding ItemName}" FontSize="20" TextWrapping="Wrap" Width="290" HorizontalAlignment="Left" VerticalAlignment="Bottom"/>
                                            </StackPanel>
                                        </StackPanel>
                                    </StackPanel>
                                </StackPanel>
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </Grid>
        </controls:PanoramaItem>
     <!--Panorama item two-->
     <!--Panorama item three-->
     <!--.................-->
    </controls:Panorama>
</Grid>

I don't want to write xaml for Panorama item two, Panorama item three and so on I think there must be some way to do it at runtime. Please help me out.
There must be some template like thing which I can use. and then fill the inner items like CurrentValue , ItemName etc. through code

I have tested below code for pivot. You can implement similar for Panaroma

Dim objPivotItem As PivotItem
Dim sScrollViewer As ScrollViewer
Dim sStackPanel As StackPanel
Dim textHeader As TextBlock
Dim txtContents As RichTextBox
For i = 0 to <Condition>

       objPivotItem = New PivotItem
       sStackPanel = New StackPanel
       sScrollViewer = New ScrollViewer
       textHeader = New TextBlock
       txtContents = New RichTextBox
'Set TextHeader properties
'Set TxtContents properties
objPivotItem.Content = sScrollViewer
sScrollViewer.Content = sStackPanel
sStackPanel.Children.Add(textHeader)
sStackPanel.Children.Add(txtContents)
objPivot.Items.Add(objPivotItem

)

Next i

You actually can set an ItemsSource property for the whole panorama control, eg:

<phone:Panorama x:Name="MyPanorama">
        <phone:Panorama.ItemTemplate>
            <DataTemplate>
                <phone:PanoramaItem Header="MyHeader">
                    <TextBlock Text="{Binding Text}"/>
                </phone:PanoramaItem>
            </DataTemplate>
        </phone:Panorama.ItemTemplate>
        <phone:Panorama.HeaderTemplate>
            <DataTemplate>
                <TextBlock Visibility="Collapsed" />
            </DataTemplate>
        </phone:Panorama.HeaderTemplate>
    </phone:Panorama>

and then, for example from the code behind:

MyPanorama.ItemsSource = myItemsCollection;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM