WPF 与Surface 2.0 SDK 亲密接触–LibraryContainer 篇
最近比较懒惰一直都没写东西,再不写笔里的墨水就快干了。看过前面关于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"));
运行效果:
按分组选择:
点击下方按钮切换为BarView 模式:
作者:李敬然(Gnie)
出处:{GnieTech} (http://www.cnblogs.com/gnielee/)
版权声明:本文的版权归作者与博客园共有。转载时须注明本文的详细链接,否则作者将保留追究其法律责任。
出处:{GnieTech} (http://www.cnblogs.com/gnielee/)
版权声明:本文的版权归作者与博客园共有。转载时须注明本文的详细链接,否则作者将保留追究其法律责任。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?