积极答复者
[WP8] Datatemplate嵌套Datatemplate

问题
-
大家好,我正在写一个WP8程序,由数据绑定,从网上返回一些信息,其中有字符串数组组成的图片地址,
我想用toolkit中的FlipView去加载这些图片(类似许多软件第一次启动时有三四个点滑动的那个效果),
而我的Pivot也是有ItemTemplate生成的,而这个ItemTemplate里面包含FlipView,FlipView里(是不是)还有DataTemple。
下面附上代码,请帮忙分析一下!感谢!
<phone:PhoneApplicationPage.Resources> <ResourceDictionary> <DataTemplate x:Key="Pivot_HeaderT"> <TextBlock FontSize="50" Text="{Binding header.Header}"/> </DataTemplate> <!-- 这里的Source应该是什么?这样写无效--> <DataTemplate x:Key="Flipview"> <Image Source="{Binding result[4].imgs}"/> </DataTemplate> <DataTemplate x:Key="Pivot_ItemT"> <ScrollViewer> <StackPanel Margin="12,0,12,0"> <!--专题新闻--> <Grid MaxHeight="200" Tap="ToNewsDetailPage"> <!--这里OK不用管,单图可以--> <Image Stretch="Uniform" Source="{Binding result[0].imgs[0]}"/> <TextBlock Name="resulttextblock" VerticalAlignment="Bottom" FontSize="20" Text="{Binding result[0].title}" TextWrapping="Wrap" Foreground="DarkGreen"/> </Grid> <!--单个视频新闻--> ... <!--列表多图新闻--> <Grid Height="200" Margin="0,12,0,0"> <Grid.RowDefinitions> <RowDefinition Height="40"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <TextBlock Grid.Row="0" FontSize="20" Text="{Binding result[4].title}"/> <toolkit:FlipView Height="150" Width="400" ItemTemplate="{StaticResource Flipview}"> <!--关键是这个ItemTemplate里面应该写什么--> <toolkit:FlipView.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </toolkit:FlipView.ItemsPanel> </toolkit:FlipView> </Grid> <!--新闻列表,包括直播新闻--> ... </StackPanel> </ScrollViewer> </DataTemplate> </ResourceDictionary> </phone:PhoneApplicationPage.Resources> <phone:Pivot Margin="0,24,0,0" Name="NewsPivot" HeaderTemplate="{StaticResource Pivot_HeaderT}" ItemTemplate="{StaticResource Pivot_ItemT}" ItemsSource="{Binding PivotDetail}" >
答案
-
自己回答了 不图省事了,直接在底下写模板
<toolkit:FlipView Grid.Row="1" ItemsSource="{Binding result[4].imgs}"> <toolkit:FlipView.ItemTemplate> <DataTemplate> <Image Source="{Binding}"/> </DataTemplate> </toolkit:FlipView.ItemTemplate> </toolkit:FlipView>
- 已标记为答案 ZetianChiang 2014年9月11日 3:39
全部回复
-
你好.Pivot 的ItemTemplate绑定它对应的DataTemplate . 虽然FlipView 是Pivot的一员,它依然可以绑定他自己的DataTemplate.不影响的.
www.bcmeng.com
- 已标记为答案 Leo (Apple) YangModerator 2014年9月10日 3:28
- 取消答案标记 ZetianChiang 2014年9月10日 7:01
-
自己回答了 不图省事了,直接在底下写模板
<toolkit:FlipView Grid.Row="1" ItemsSource="{Binding result[4].imgs}"> <toolkit:FlipView.ItemTemplate> <DataTemplate> <Image Source="{Binding}"/> </DataTemplate> </toolkit:FlipView.ItemTemplate> </toolkit:FlipView>
- 已标记为答案 ZetianChiang 2014年9月11日 3:39