我正在开发一个windows通用应用程序,我有一个2页的FlipView,每一页包含4个按钮,我希望当我从page1上滚动时,我得到了page2,我试着这样做:
<Page.Resources>
<DataTemplate x:Key="FlipViewItemTemplate">
<Grid Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Grid.Column="0" Grid.Row="0" />
<Button Grid.Column="0" Grid.Row="1" />
<Button Grid.Column="1" Grid.Row="0" />
<Button Grid.Column="1" Grid.Row="1" />
</Grid>
</DataTemplate>
<DataTemplate x:Key="FlipViewItemTemplate1">
<Grid Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Grid.Column="0" Grid.Row="0" />
<Button Grid.Column="0" Grid.Row="1" />
<Button Grid.Column="1" Grid.Row="0" />
<Button Grid.Column="1" Grid.Row="1" />
</Grid>
</DataTemplate>
</Page.Resources我从名为flipView的flipView1中调用了这个方法:
private void flipView1_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
flipView1.ItemTemplate = Resources["FlipViewItemTemplate"] as DataTemplate;
}我得到的是一个没有滚动的4个按钮的页面,有什么方法可以在滚动中显示不同的页面吗?
谢谢你的帮助
发布于 2015-12-08 13:03:10
可能是使用DataTemplateSelector的解决方案
下面是一个示例: 1)类必须从ExploringOfficeRestAPI.Styles.DataTemplateSelectors (公共类FileFolderDataTemplateSelector : DataTemplateSelector { public DataTemplate FileTemplate { get;set;} public DataTemplate FolderTemplate { get;set;}
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container) { var viewModelPublic = item as OneDrivePublicFile; if (viewModelPublic != null) { if (viewModelPublic.IsFile()) { return FileTemplate; } return FolderTemplate;
}
return FolderTemplate;
}
}} 2)定义XAML DataTemplate : Grid.Row="0“Grid.RowSpan="2”“Margin="0”VerticalAlignment=“拉伸”Height="150“Width="150”
SelectionHighlightColor="{StaticResource EORAForegroundBrush}"/> Grid.Row="0" Margin="0,0,10,0" VerticalAlignment="Top" HorizontalAlignment="Right"/> Grid.Row="1" Margin="10,0,0,-20" VerticalAlignment="Bottom" /> </Grid>
</DataTemplate>
<DataTemplate x:Key="FileTemplate">
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Image Source="{Binding ThumbnailUrl}" Width="150" Height="150" Margin="0,0,0,0" Grid.RowSpan="2" VerticalAlignment="Top" />
<TextBlock Text="{Binding name}" Foreground="{StaticResource EORAForegroundBrush}"
Style="{StaticResource EORATextBlockStyle}" Width="auto" Height="50"
Grid.Row="1" Margin="10,0,0,-20" VerticalAlignment="Bottom" HorizontalAlignment="Left" />
</Grid>
</DataTemplate>3)在您的xmlns:selector="using:ExploringOfficeRestAPI.Styles.DataTemplateSelectors“:XAMl中定义选择器
<selector:FileFolderDataTemplateSelector
x:Key="FileFolderDataTemplateSelector"
FolderTemplate="{StaticResource FolderTemplate}"
FileTemplate="{StaticResource FileTemplate}"/>4)最后定义ItemTemplateSelector="{StaticResource FileFolderDataTemplateSelector}“以表示FlipView
https://stackoverflow.com/questions/34133567
复制相似问题