博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WPF 与Surface 2.0 SDK 亲密接触–LibraryContainer 篇
阅读量:6981 次
发布时间:2019-06-27

本文共 1888 字,大约阅读时间需要 6 分钟。

最近比较懒惰一直都没写东西,再不写笔里的墨水就快干了。看过前面关于LibraryStack 和LibraryBar 的介绍后,大家可能已经对Library 控件系列有了进一步了解,本篇将继续介绍LibraryContainer,它其实就是LibraryStack、LibrayBar 的集合体。
     首先,我们仍然需要创建一个DataTemplate 用来控制LibraryStack、LibrayBar 的显示样式。然后新建一个LibraryContainer,在其中增加StackView 和BarView 两种浏览模式。
<s:SurfaceWindow.Resources>
    <DataTemplate x:Key="LibraryBarItemTemplate">
        <Grid >
            <Image Source="{Binding Bitmap}"/>
            <Label FontSize="14" Content="{Binding Label}"/>
        </Grid>
    </DataTemplate>
</s:SurfaceWindow.Resources>
<Grid>
    <s:LibraryContainer x:Name="mlibraryContainer">
        <s:LibraryContainer.StackView>
            <s:StackView ItemTemplate="{StaticResource LibraryBarItemTemplate}"/>
        </s:LibraryContainer.StackView>
        <s:LibraryContainer.BarView>
            <s:BarView ItemTemplate="{StaticResource LibraryBarItemTemplate}"/>
        </s:LibraryContainer.BarView>
    </s:LibraryContainer>
</Grid>
     与上一篇LibraryBar 一样我们继续使用分组的浏览模式,按GroupName 进行分组操作,PhotoAlbum 类请参考这里。
ObservableCollection<PhotoAlbum> items = new ObservableCollection<PhotoAlbum>();
string imagesPath = @"C:\Users\Public\Pictures\Sample Pictures\";
items.Add(new PhotoAlbum(imagesPath + "Hydrangeas.jpg", "Hydrangeas", "Nature"));
items.Add(new PhotoAlbum(imagesPath + "Lighthouse.jpg", "Lighthouse", "Nature"));
items.Add(new PhotoAlbum(imagesPath + "Tulips.jpg", "Tulips", "Nature"));
items.Add(new PhotoAlbum(imagesPath + "Jellyfish.jpg", "Jellyfish", "Animal"));
items.Add(new PhotoAlbum(imagesPath + "Koala.jpg", "Koala", "Animal"));
items.Add(new PhotoAlbum(imagesPath + "Penguins.jpg", "Penguins", "Animal"));
mlibraryContainer.ItemsSource = items;
ICollectionView defaultView = CollectionViewSource.GetDefaultView(items);
defaultView.GroupDescriptions.Add(new PropertyGroupDescription("GroupName"));
运行效果:
Capture
按分组选择:
Capture2 Capture4
点击下方按钮切换为BarView 模式:
Capture3
本文转自Gnie博客园博客,原文链接:http://www.cnblogs.com/gnielee/archive/2011/08/26/wpf-surface2sdk-librarycontainer.html,如需转载请自行联系原作者
你可能感兴趣的文章
Spring的容器内部事件发布
查看>>
mongoDB Indexing Advice
查看>>
跟我学Kafka之NIO通信机制
查看>>
关于版本管理
查看>>
1 Java NIO概述-翻译
查看>>
图像延迟加载 && 列表图顺序加载
查看>>
MySQL 基础架构你不知道的那些事!
查看>>
Vue学习笔记(1)——在页面右上角实现可悬浮/隐藏的系统菜单
查看>>
UITableView占位图的低耦合性设计
查看>>
一个女装小程序的瀑布流实现
查看>>
Docker实现Mariadb分库分表、读写分离
查看>>
Node.js核心内容
查看>>
github克隆本地项目
查看>>
j抽奖
查看>>
GMQ力争为全球区块链数字资产技术应用贡献一份力量
查看>>
VUE+Vant 实现图片上传
查看>>
ajax实现点击加载更多
查看>>
为什么JavaScript没有类而使用原型?——JavaScript语言特性来历
查看>>
TarsGo新版本发布,支持protobuf,zipkin和自定义插件
查看>>
Flutter 如何创建并发布 Plugin (VS Code + GitHub 发布)
查看>>