主要参照了DevExpress的PhotoGallery实例的实现。

效果如下:

照片墙核心代码如下:

PhotoGallery.xaml

<local:CarouselDemoModule x:Class="PictureMagic.PhotoGallery"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxca="http://schemas.devexpress.com/winfx/2008/xaml/carousel"
xmlns:dxdb="http://schemas.devexpress.com/winfx/2008/xaml/demobase"
xmlns:local="clr-namespace:PictureMagic"
xmlns:collection="clr-namespace:System.Collections;assembly=mscorlib"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" >
<dxdb:DemoModuleControl>
<Grid ClipToBounds="False" Background="#FFB6C1">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition Height="" />
</Grid.RowDefinitions>
<dxca:CarouselPanel RenderOptions.BitmapScalingMode="HighQuality"
x:Name="carousel"
AnimationTime=""
VisibleItemCount=""
AttractorPointIndex=""
PathSizingMode="Stretch"
PathPadding="10,5,10,20"
IsAutoSizeItem="True"
ClipToBounds="True"
PathVisible="False"
IsInvertedDirection="True"
Grid.RowSpan=""
IsRepeat="True"
ItemSize="100,100" >
<dxca:CarouselPanel.Resources>
<ControlTemplate x:Key="itemTemplate" TargetType="{x:Type ContentControl}">
<Grid VerticalAlignment="Center">
<Border Margin="3,3,0,0" Background="Black" Opacity="0.25" CornerRadius="" />
<Border Margin="0,0,3,3" Padding="" BorderBrush="#5F000000" BorderThickness="" Background="White">
<Image Source="{Binding Path=DataContext, RelativeSource={RelativeSource TemplatedParent}}" Stretch="Uniform" />
</Border>
</Grid>
</ControlTemplate>
<Style TargetType="{x:Type FrameworkElement}" x:Key="itemStyle">
<Setter Property="RenderTransformOrigin" Value="0.5, 0.5" />
<Setter Property="Opacity" Value="{Binding Path=(dxca:CarouselPanel.Parameters).Opacity, RelativeSource={RelativeSource Self}}" />
<Setter Property="Panel.ZIndex" Value="{Binding Path=(dxca:CarouselPanel.Parameters).ZIndex, Converter={local:DoubleToIntConverter}, RelativeSource={RelativeSource Self}}" />
<Setter Property="RenderTransform">
<Setter.Value>
<TransformGroup>
<ScaleTransform ScaleX="{Binding Path=(dxca:CarouselPanel.Parameters).Scale, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContentControl}}}"
ScaleY="{Binding Path=(dxca:CarouselPanel.Parameters).Scale, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContentControl}}}"
/>
<TranslateTransform X="{Binding Path=(dxca:CarouselPanel.Parameters).OffsetX, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContentControl}}}"
Y="{Binding Path=(dxca:CarouselPanel.Parameters).OffsetY, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContentControl}}}"
/>
</TransformGroup>
</Setter.Value>
</Setter>
</Style>
</dxca:CarouselPanel.Resources>
<dxca:CarouselPanel.ParameterSet>
<dxca:ParameterCollection>
<dxca:Parameter Name="Opacity" DistributionFunction="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type dxca:CarouselPanel}, ResourceId=Linear3PConvexNr}}" />
<dxca:Parameter Name="Scale" DistributionFunction="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type dxca:CarouselPanel}, ResourceId=Linear3PConvexNr}}" />
<dxca:Parameter Name="ZIndex" DistributionFunction="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type dxca:CarouselPanel}, ResourceId=Linear3PConvexERIntMax}}" />
</dxca:ParameterCollection>
</dxca:CarouselPanel.ParameterSet>
<dxca:CarouselPanel.ItemMovingPath>
<PathGeometry Figures="M255,0 C352.86864,0.5 454.5,61.389274 454.5,136.5 C454.5,211.61073 352.86864,272.5 227.5,272.5 C102.13136,272.5 0.5,211.61073 0.5,136.5 C0.5,61.389274 102.13136,0.5 200,0.5 " />
</dxca:CarouselPanel.ItemMovingPath>
</dxca:CarouselPanel>
<dxdb:ImageControl Margin="30,30,30,0" Source="{Binding ElementName=carousel, Path=ActiveItem.DataContext}" VerticalAlignment="Center" HorizontalAlignment="Center" />
<dxca:CarouselNavigator
VerticalAlignment="Center"
HorizontalAlignment="Center"
MinHeight=""
MinWidth=""
Grid.Row=""
Carousel="{Binding ElementName=carousel}"
/>
</Grid>
</dxdb:DemoModuleControl>
</local:CarouselDemoModule>

PhotoGallery.xaml.cs

using System.Windows;
using System.Windows.Controls;
using DevExpress.Xpf.Carousel;
using System.Collections.Generic; namespace PictureMagic
{
public partial class PhotoGallery : CarouselDemoModule { private List<PicutureInfo> m_picureInfoList = null;
public PhotoGallery() {
InitializeComponent();
m_picureInfoList = new List<PicutureInfo>();
}
protected override void AddItems(string path, ItemType it, CarouselPanel carousel) {
var items = CreateItems(path, it);
foreach (var item in items) {
ContentControl control = new ContentControl();
control.Template = carousel.Resources["itemTemplate"] as ControlTemplate;
control.Style = carousel.Resources["itemStyle"] as Style;
control.DataContext = ((Image)item).Source;
carousel.Children.Add(control);
}
} public void ShowNextImage()
{
carousel.MoveNext();
} public void SearchImage(string path)
{
carousel.Children.Clear();
AddItems(path, ItemType.BinaryImage, carousel);
}
}
}

CarouselDemoModule.cs

using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using DevExpress.Utils;
using DevExpress.Xpf.Carousel;
using DevExpress.Xpf.DemoBase; namespace PictureMagic
{
public class CarouselDemoModule : DemoModule
{
static CarouselDemoModule()
{
Type ownerType = typeof(CarouselDemoModule);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
CommandManager.InvalidateRequerySuggested();
}
protected virtual List<FrameworkElement> CreateItems(string path, ItemType it)
{
ContentLoadHelper contentLoadHelper = new ContentLoadHelper();
contentLoadHelper.Path = path;
var itemList = new List<FrameworkElement>(contentLoadHelper.LoadItems(it).ToArray());
for (int i = ; i < itemList.Count; i++)
{
itemList[i].Name = "Item" + i.ToString();
((Image)itemList[i]).Stretch = System.Windows.Media.Stretch.Fill;
}
return itemList;
}
protected virtual void AddItems(string path, ItemType it, CarouselPanel carousel)
{
var itemList = CreateItems(path, it);
foreach (var item in itemList)
{
item.Name = "item" + carousel.Children.Count;
carousel.Children.Add(item);
}
}
}
}

Utils.cs

using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Data;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging; namespace PictureMagic
{
public enum ItemType { BinaryImage, DrawingImage }
public class ContentLoadHelper
{
public string Path { get; set; }
public ContentLoadHelper()
{
}
public List<FrameworkElement> LoadItems(ItemType it)
{
LoadDelegate loadDelegate = null;
switch (it)
{
case ItemType.BinaryImage:
loadDelegate = LoadImage;
break;
case ItemType.DrawingImage:
// loadDelegate = LoadDrawingImage;
break;
}
var items = new List<FrameworkElement>();
if (loadDelegate != null)
{
DirectoryInfo folder = new DirectoryInfo(Path); foreach (FileInfo file in folder.GetFiles("*.*"))
{
if (IsPhotoFile(file.Extension))
{
items.Add(loadDelegate(file.FullName));
}
}
}
return items;
} private bool IsPhotoFile(string extension)
{
string[] exArray = { ".PNG", ".JPG", ".BMP", ".GIF", ".JPEG" };
foreach (string strExe in exArray)
{
if (extension.ToUpper().Equals(strExe))
{
return true;
}
}
return false;
} public delegate FrameworkElement LoadDelegate(string strPath);
public Image LoadDrawingImage(Stream stream)
{
var rd = (ResourceDictionary)XamlReader.Load(stream);
var di = (DrawingImage)rd["Layer_1"];
return new Image() { Source = di };
}
public Image LoadImage(string strPath)
{
var image = new Image();
image.Source = new BitmapImage(new Uri(strPath));
return image;
}
} public class DoubleToIntConverter : MarkupExtension, IValueConverter
{
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (targetType != typeof(int))
throw new InvalidOperationException();
return (int)((double)value);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
}

  

WPF 照片墙的实现的更多相关文章

  1. 牛逼哄哄的Qt库

    目录 一.有价值 - 好的网站 - 好的文章 二.Qt开源库-工具 - QtXlsx--excel读写库 三.Qt开源库-控件 - libqxt编译 - Qwt - QCustomPlot - 其他 ...

  2. WPF 制作聊天窗口获取历史聊天记录

    腾讯从QQ2013版起开始在聊天记录里添加了历史记录查看功能,个人聊天窗口可以点击最上边的‘查看历史消息’,而群组里的未读消息可以通过滚动鼠标中键或者拖动滚动条加载更多消息,那这个用wpf怎么实现呢? ...

  3. wpf 自定义窗口,最大化时不覆盖任务栏

    相信很多人使用wpf时会选择自定义美观的窗口,因此会设置WindowStyle="None" 取消自带的标题栏.但这样使用 WindowState="Maximized& ...

  4. 在WPF中使用依赖注入的方式创建视图

    在WPF中使用依赖注入的方式创建视图 0x00 问题的产生 互联网时代桌面开发真是越来越少了,很多应用都转到了浏览器端和移动智能终端,相应的软件开发上的新技术应用到桌面开发的文章也很少.我之前主要做W ...

  5. MVVM框架从WPF移植到UWP遇到的问题和解决方法

    MVVM框架从WPF移植到UWP遇到的问题和解决方法 0x00 起因 这几天开始学习UWP了,之前有WPF经验,所以总体感觉还可以,看了一些基础概念和主题,写了几个测试程序,突然想起来了前一段时间在W ...

  6. MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息

    MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二 ...

  7. MVVM模式解析和在WPF中的实现(五)View和ViewModel的通信

    MVVM模式解析和在WPF中的实现(五) View和ViewModel的通信 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 M ...

  8. MVVM设计模式和WPF中的实现(四)事件绑定

    MVVM设计模式和在WPF中的实现(四) 事件绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

  9. MVVM模式解析和在WPF中的实现(三)命令绑定

    MVVM模式解析和在WPF中的实现(三) 命令绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

随机推荐

  1. python_20_socket

    什么是socket? -- 通过各种协议,发送和接收数据,实现网络通信 -- 在python3中,网络发送只能发二进制数据 OSI七层模型是什么? 应用 表示 会话 传输 网络             ...

  2. 1.JavaScript 教程:基础语法

    简介: JavaScript web 开发人员必须学习的 3 门语言中的一门: HTML 定义了网页的内容 CSS 描述了网页的布局 JavaScript 网页的行为 用法: (1)HTML 中的脚本 ...

  3. java8大基本数据类型

    基本类型 字节数 位数 最大值 最小值 byte 1byte 8bit 2^7 - 1 -2^7 short 2byte 16bit 2^15 - 1 -2^15 int 4byte 32bit 2^ ...

  4. Linux用户登录记录日志和相关查看命令汇总

    # 1 utmp.wtmp.btmp文件 Linux用户登录信息放在三个文件中: 1 /var/run/utmp:记录当前正在登录系统的用户信息,默认由who和w记录当前登录用户的信息,uptime记 ...

  5. 无法远程连接SQLSERVER2000的解决方法

    有时候客户端和服务器不在同一个局域网里面,这时候很可能无法直接使用服务器名称来标识该服务器,这时候我们可以使用HOSTS文件来进行名字解析,具体的方法是: 1.使用记事本打开HOSTS文件(一般情况下 ...

  6. poj 1423 打表/斯特林公式

    对于n位数的计算,我们可以采用(int)log10(n) + 1的方法得到n的位数 第一种方法: 对于n!位数的计算,log10(n!) = log10(1) + log10(2) + ... + l ...

  7. 6.Ray-消息订阅器编写

    消息订阅器: Ray是基于Event Sourcing设计的ES/Actor框架,消息发布后需要订阅处理,订阅器主要有以下两类: CoreHandler消息订阅器=RabbitSub+SubHandl ...

  8. CSS中的字体属性和文本属性

    1.CSS字体的属性 font 简写,作用是把所有的针对字体的属性设置在一个声明中 font-family 设置字体系列 font-size 设置字体尺寸 font-style 设置字体风格,ital ...

  9. xBIM IFC 层次结构

    目录 xBIM 应用与学习 (一) xBIM 应用与学习 (二) xBIM 基本的模型操作 xBIM 日志操作 XBIM 3D 墙壁案例 xBIM 格式之间转换 xBIM 使用Linq 来优化查询 x ...

  10. verilog实验3:AD转换后串口输出到PC端

    一.实验任务 通过tcl549AD转换芯片将模拟电压信号转换为数字信号,并通过串口显示到电脑上.此AD转换芯片为串行转换芯片,且转换速率要和串口选择的速率匹配.等待串口发送完后,再进行下一次AD转换. ...