【问题标题】:Fill panorama item dynamically in wp7在wp7中动态填充全景项目
【发布时间】:2013-05-06 07:12:15
【问题描述】:

我想动态地在我的应用程序中添加全景项目。项目数(3 到 7)取决于我得到的 json 响应。目前为了测试,我在 xaml 中创建了 4 个项目,它对我有用,但它不是动态的。这是我的 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>

我不想为全景项目二、全景项目三等编写 xaml,我认为在运行时必须有一些方法可以做到这一点。请帮帮我。
必须有一些模板之类的东西我可以使用。然后通过代码填充CurrentValueItemName等内部项目

【问题讨论】:

    标签: c# .net silverlight windows-phone-7 xaml


    【解决方案1】:

    我已经测试了下面的枢轴代码。您可以为 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
    

    【讨论】:

    • 我没有得到你的解决方案,我认为它不在 c# 中。
    【解决方案2】:

    您实际上可以为整个全景控件设置 ItemsSource 属性,例如。 g.:

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

    然后,例如从后面的代码:

    MyPanorama.ItemsSource = myItemsCollection;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-18
      • 1970-01-01
      相关资源
      最近更新 更多