这个功能之前用wpf写过一次这次用Silverlight写一次

这两种写法上基本上没有太大的差别

这个Demo并不完美,只是给大家提供一个思路

源码:SilverLightListPricture.rar

看一下效果

思路是:

修改ItemTemplate样式

ItemsPanelTemplate 用WrapPanel显示

先为image绑定图片添加一个转换类

using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes; namespace SilverLightListPricture
{
public class ConvertToRecipesImageInfo : IValueConverter
{ public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{ Stream _stream = value as Stream;
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(_stream);
return bitmap; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

我先把前端代码分解一下最后给出全部代码
先看一下是怎么修改listbox的ItemTemplate

是用一个image和一个*button做删除

 <DataTemplate x:Key="ItemTemplate">
<Grid Width="" Height="" >
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions> <Border BorderThickness="" BorderBrush="SteelBlue" CornerRadius="">
<Grid Margin="">
<Grid.RowDefinitions>
<RowDefinition Height=""></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Image Grid.Row="" Source="{Binding Path=streamsInfo,Converter={StaticResource ImageConverter}}" Margin="" ></Image>
<StackPanel Grid.Row="" HorizontalAlignment="Right" >
<Button Width="" BorderThickness="" Background="Transparent" Click="Del_PrictureEvent" Name="btn_Del" Tag="{Binding Path=activePricture}" Style="{StaticResource CloseButton}" >
</Button>
</StackPanel>
</Grid>
</Border>
</Grid>
</DataTemplate>

button的样式

<Style x:Key="CloseButton" TargetType="Button">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="Transparent">
<Canvas>
<Line X1="" Y1="" X2="" Y2="" Stroke="#9FA1A0" StrokeThickness=""></Line>
<Line X1="" Y1="" X2="" Y2="" Stroke="#9FA1A0" StrokeThickness=""></Line>
</Canvas>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

listbox用的时候要把它的ItemsPanelTemplate改用WrapPanel

重要的是ScrollViewer.HorizontalScrollBarVisibility是定要为Disabled这样就能防止wrapPanel横向滚动条出现

 <ListBox Grid.Row=""   Margin="" Width="" Name="lsPricture"  ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ItemTemplate="{StaticResource ItemTemplate}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate> <tools:WrapPanel Width="Auto" Background="#F3FFFF" >
</tools:WrapPanel> </ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>

完整的前台代码

<UserControl x:Class="SilverLightListPricture.ListBoxPrictueDEMO"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:convertImage="clr-namespace:SilverLightListPricture"
xmlns:tools="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"> <UserControl.Resources>
<convertImage:ConvertToRecipesImageInfo x:Key="ImageConverter"/>
<!--关闭按钮样式-->
<Style x:Key="CloseButton" TargetType="Button">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="Transparent">
<Canvas>
<Line X1="" Y1="" X2="" Y2="" Stroke="#9FA1A0" StrokeThickness=""></Line>
<Line X1="" Y1="" X2="" Y2="" Stroke="#9FA1A0" StrokeThickness=""></Line>
</Canvas>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<DataTemplate x:Key="ItemTemplate">
<Grid Width="" Height="" >
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions> <Border BorderThickness="" BorderBrush="SteelBlue" CornerRadius="">
<Grid Margin="">
<Grid.RowDefinitions>
<RowDefinition Height=""></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Image Grid.Row="" Source="{Binding Path=streamsInfo,Converter={StaticResource ImageConverter}}" Margin="" ></Image>
<StackPanel Grid.Row="" HorizontalAlignment="Right" >
<Button Width="" BorderThickness="" Background="Transparent" Click="Del_PrictureEvent" Name="btn_Del" Tag="{Binding Path=activePricture}" Style="{StaticResource CloseButton}" >
</Button>
</StackPanel>
</Grid>
</Border>
</Grid>
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height=""></RowDefinition>
<RowDefinition Height=""></RowDefinition>
</Grid.RowDefinitions>
<ListBox Grid.Row="" Margin="" Width="" Name="lsPricture" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ItemTemplate="{StaticResource ItemTemplate}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate> <tools:WrapPanel Width="Auto" Background="#F3FFFF" >
</tools:WrapPanel> </ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox> <StackPanel Grid.Row="" VerticalAlignment="Center" HorizontalAlignment="Center" Orientation="Horizontal">
<Button Content="添加 " Width="" Click="btn_AddEvent"></Button>
</StackPanel>
</Grid>
</UserControl>

后台代码

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes; namespace SilverLightListPricture
{
public partial class ListBoxPrictueDEMO : UserControl
{
ObservableCollection<ImageInfo> SourceCollection = new ObservableCollection<ImageInfo>();
public ListBoxPrictueDEMO()
{
InitializeComponent();
bindSource();
}
//删除
public void Del_PrictureEvent(object sender, RoutedEventArgs e)
{ }
void bindSource()
{
lsPricture.ItemsSource = SourceCollection;
} public void btn_AddEvent(object sender, RoutedEventArgs e)
{ OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "图片文件(*.jpg,*.png,*.bmp)|*.jpg;*.png;*.bmp|All Files (*.*)|*.*";
if (openFileDialog.ShowDialog() == true)
{
FileInfo file = openFileDialog.File; Stream stream = file.OpenRead(); SourceCollection.Add(new ImageInfo { streamsInfo = stream, activePricture = "tag" }); }
}
} public class ImageInfo
{
public string activePricture
{
get;
set;
}
public Stream streamsInfo
{
get;
set;
}
}
}

好了就说到这

源码:SilverLightListPricture.rar

silverlight ListBox 多列图片效果的更多相关文章

  1. NOPI导出execl 多个sheet,一列图片

    NPOI API: http://www.cnblogs.com/atao/archive/2009/11/15/1603528.html http://blog.csdn.net/pan_junbi ...

  2. javascript设计模式实践之职责链--具有百叶窗切换图片效果的JQuery插件(三)

    在上一篇<javascript设计模式实践之模板方法--具有百叶窗切换图片效果的JQuery插件(二)>里,通过采用模板方法模式完成了切换效果对象的构建编写. 接下来就是完成各效果对象的调 ...

  3. javascript设计模式实践之模板方法--具有百叶窗切换图片效果的JQuery插件(二)

    在上一篇<javascript设计模式实践之迭代器--具有百叶窗切换图片效果的JQuery插件(一)>里,通过采用迭代器模式完成了各初始化函数的定义和调用. 接下来就要完成各个切换效果的编 ...

  4. javascript设计模式实践之迭代器--具有百叶窗切换图片效果的JQuery插件(一)

    类似于幻灯片的切换效果,有时需要在网页中完成一些图片的自动切换效果,比如广告,宣传,产品介绍之类的,那么单纯的切就没意思了,需要在切换的时候通过一些效果使得切换生动些. 比较常用之一的就是窗帘切换了. ...

  5. JQuery 表格拖动调整列宽效果

    类似于桌面程序中的表格拖动表头的效果,当鼠标停留在表头边框线上时,鼠标会变成表示左右拖动的形状,接着拖动鼠标,会在表格中出现一条随鼠标移动的竖线,最后放开鼠标,表格列宽会被调整.最近比较空闲,便自己动 ...

  6. js矩阵菜单或3D立体预览图片效果

    js矩阵菜单或3D立体预览图片效果 下载地址: http://files.cnblogs.com/elves/js%E7%9F%A9%E9%98%B5%E8%8F%9C%E5%8D%95%E6%88% ...

  7. ArcGIS API for Silverlight之配准JPG图片地图文字倾斜解决方案

    原文:ArcGIS API for Silverlight之配准JPG图片地图文字倾斜解决方案 根据实际JPG图片进行配准后,发布的地图,利用ArcGIS API for Silverlight在网页 ...

  8. Android 使用ContentProvider扫描手机中的图片,仿微信显示本地图片效果

    版权声明:本文为博主原创文章,未经博主允许不得转载. 转载请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/1873 ...

  9. Android Glide加载图片时转换为圆形、圆角、毛玻璃等图片效果

     Android Glide加载图片时转换为圆形.圆角.毛玻璃等图片效果 附录1简单介绍了Android开源的图片加载框架.在实际的开发中,虽然Glide解决了快速加载图片的问题,但还有一个问题悬 ...

随机推荐

  1. sql server 2005 32位+64位、企业版+标准版、CD+DVD 下载地址大全 .

    企业版DVD SQL Server 2005 Enterprise Edition(支持超大型企业) 32 位DVD: ed2k://|file|cs_sql_2005_ent_x86_dvd.iso ...

  2. nopcommerce之权限模块

    这篇文章简单介绍一下nopcommerce的权限模块,nopcommerce里面的权限设计相对比较简单,主要针对后台的action和前台的是否显示(比如产品.品牌等),虽然简单但是应付一般的项目应该没 ...

  3. hdu2527哈夫曼编码

    /* Safe Or Unsafe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...

  4. NOIP2008提高组(前三题) -SilverN

    此处为前三题,第四题将单独发布 火柴棒等式 题目描述 给你n根火柴棍,你可以拼出多少个形如“A+B=C”的等式?等式中的A.B.C是用火柴棍拼出的整数(若该数非零,则最高位不能是0).用火柴棍拼数字0 ...

  5. hdu-4810 Wall Painting(组合数学)

    题目链接: Wall Painting Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  6. codeforces 484B B. Maximum Value(二分)

    题目链接: B. Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standa ...

  7. UESTC 878 温泉旅馆 --性质+枚举

    设FA为A的牌中数字异或和,FB为B的. 则有性质: ans = (所有的(A&B=0)个数 + (FA=FB且A&B=0)的个数)/2.即所有的FA>FB的个数(除2是因为这里 ...

  8. Codeforces Round 261 Div.2 D Pashmak and Parmida's problem --树状数组

    题意:给出数组A,定义f(l,r,x)为A[]的下标l到r之间,等于x的元素数.i和j符合f(1,i,a[i])>f(j,n,a[j]),求有多少对这样的(i,j). 解法:分别从左到右,由右到 ...

  9. redis 一二事 - 设置过期时间,以文件夹形式展示key显示缓存数据

    在使用redis时,有时回存在大量数据的时候,而且分类相同,ID相同 可以使用hset来设置,这样有一个大类和一个小分类和一个value组成 但是hset不能设置过期时间 过期时间只能在set上设置 ...

  10. Bluestacks 使用

    Bluestack介绍 一款能够在PC模拟Android的好用模拟器 官网:http://www.bluestacks.cn/ 早在2012年就使用上它了,但一直未发现他的许多优点,在使用过其它的两款 ...