简体   繁体   English

在wp7中动态填充全景图项目

[英]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. 项目(3到7)的数量取决于我得到的json响应。 Presently for testing I created 4 items in xaml and it works for me but its not dynamic. 目前,为了测试,我在xaml中创建了4个项目,它对我有用,但不是动态的。 Here is my xaml. 这是我的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. 我不想为Panorama项目2,Panorama项目3编写xaml,以此类推,我认为在运行时必须有某种方法可以做到。 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 然后通过代码填充内部项目,如CurrentValueItemName

I have tested below code for pivot. 我已经测试了下面的数据透视。 You can implement similar for Panaroma 您可以为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: 实际上,您可以为整个全景图控件设置ItemsSource属性,例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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