我动态地希望在我的应用程序中添加全景项。项目(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>
我不想为Panorama第二项,Panorama第三项等编写xaml,我认为必须有一些方法可以在运行时完成。请帮帮我 必须有一些我可以使用的模板。然后通过代码
填充CurrentValue
,ItemName
等内部条目
答案 0 :(得分:0)
我已经测试了下面的代码代码。你可以为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
答案 1 :(得分:0)
您实际上可以为整个全景控件设置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;