首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SelectionChanged与FlipView

SelectionChanged与FlipView
EN

Stack Overflow用户
提问于 2015-12-07 12:27:47
回答 1查看 96关注 0票数 0

我正在开发一个windows通用应用程序,我有一个2页的FlipView,每一页包含4个按钮,我希望当我从page1上滚动时,我得到了page2,我试着这样做:

代码语言:javascript
复制
<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中调用了这个方法:

代码语言:javascript
复制
private void flipView1_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
  {
   flipView1.ItemTemplate = Resources["FlipViewItemTemplate"] as DataTemplate;
   }

我得到的是一个没有滚动的4个按钮的页面,有什么方法可以在滚动中显示不同的页面吗?

谢谢你的帮助

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-08 13:03:10

DataTemplateSelector

可能是使用DataTemplateSelector的解决方案

下面是一个示例: 1)类必须从ExploringOfficeRestAPI.Styles.DataTemplateSelectors (公共类FileFolderDataTemplateSelector : DataTemplateSelector { public DataTemplate FileTemplate { get;set;} public DataTemplate FolderTemplate { get;set;}

代码语言:javascript
复制
     protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)         {             var viewModelPublic = item as OneDrivePublicFile;             if (viewModelPublic != null)             {                 if (viewModelPublic.IsFile())                 {                     return FileTemplate;                 }
代码语言:javascript
复制
            return FolderTemplate;
        }          
        return FolderTemplate;

    }
}

} 2)定义XAML DataTemplate : Grid.Row="0“Grid.RowSpan="2”“Margin="0”VerticalAlignment=“拉伸”Height="150“Width="150”

代码语言:javascript
复制
                            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" />
代码语言:javascript
复制
    </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中定义选择器

代码语言:javascript
复制
        <selector:FileFolderDataTemplateSelector 
                    x:Key="FileFolderDataTemplateSelector" 
                    FolderTemplate="{StaticResource FolderTemplate}"
                    FileTemplate="{StaticResource FileTemplate}"/>

4)最后定义ItemTemplateSelector="{StaticResource FileFolderDataTemplateSelector}“以表示FlipView

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34133567

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档