欢迎访问 生活随笔!

凯发k8官方网

当前位置: 凯发k8官方网 > > 编程问答 >内容正文

编程问答

silverlight listbox 多列图片效果 -凯发k8官方网

发布时间:2025/1/21 编程问答 11 豆豆
凯发k8官方网 收集整理的这篇文章主要介绍了 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

这个功能之前用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做删除

"itemtemplate">"200" height="210" >"1" borderbrush="steelblue" cornerradius="3">"0">"185">"0" source="{binding path=streamsinfo,converter={staticresource imageconverter}}" margin="0" >"1" horizontalalignment="right" >

 


button的样式


listbox用的时候要把它的itemspaneltemplate改用wrappanel

重要的是scrollviewer.horizontalscrollbarvisibility是定要为disabled这样就能防止wrappanel横向滚动条出现

"0" margin="5" width="640" name="lspricture" scrollviewer.verticalscrollbarvisibility="visible" scrollviewer.horizontalscrollbarvisibility="disabled"itemtemplate="{staticresource itemtemplate}">"auto" background="#f3ffff" >


完整的前台代码

"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">"imageconverter"/>"itemtemplate">"200" height="210" >"1" borderbrush="steelblue" cornerradius="3">"0">"185">"0" source="{binding path=streamsinfo,converter={staticresource imageconverter}}" margin="0" >"1" horizontalalignment="right" >"layoutroot" background="white">"600">"73">"0" margin="5" width="640" name="lspricture" scrollviewer.verticalscrollbarvisibility="visible" scrollviewer.horizontalscrollbarvisibility="disabled"itemtemplate="{staticresource itemtemplate}">"auto" background="#f3ffff" >"1" verticalalignment="center" horizontalalignment="center" orientation="horizontal">

后台代码

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 sourcecollection = new observablecollection();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

 

 

      

总结

以上是凯发k8官方网为你收集整理的的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得凯发k8官方网网站内容还不错,欢迎将凯发k8官方网推荐给好友。

网站地图