silverlight image绑定bitmap( Binding Image.Source from downloaded memory)
2012-11-08 15:10
501 查看
首先xaml前台image的source是用string表示的 如:<imagesource="1.jpg"/> 想当然地以为source="{Bindingimagesource}",imagesource也是必须是string,结果闹了我一个下午。 给后来人留点脚印,想想前者探索的艰辛啊。。 首先看看这段代码 <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="ListBoxSilde.UserControl1"> <Gridx:Name="LayoutRoot"> <ImageSource="{BindingImage}"Stretch="None"x:Name="img"></Image> </Grid> </UserControl> cs部分: usingSystem.Windows.Controls; namespaceListBoxSilde { publicpartialclassUserControl1:UserControl { Testt; publicUserControl1() { InitializeComponent(); t=newTest(){Image="1.jpg"}; img.DataContext=t; } } publicclassTest{publicstringImage{set;get;}} } 再来看看另一种情况,要绑定的image是下载下来的byte[],没有路径,这时候 <ImageStretch="None"Source="{BindingimageSource}"x:Name="img"></Image> cs: publicclassbook//定义一个book类,需要绑定imagesource用ImageSource类型 { publicstringbookname{get;set;} publicImageSourceimagesource{get;set;} } voidGetFirstImageCompleted(objectsender,GetFirstImageCompletedEventArgse) { ms=newMemoryStream(e.Result);//byte[]转stream BitmapImageimage=newBitmapImage(); image.SetSource(ms); bookb=newbook(); b.imagesource=image; img.DataContext=b;//绑定对象 } 很显然,image.source绑定对象可以是ImageSource和string,事情就是这样。
技术交流群:29609188
相关文章推荐
- image绑定bitmap( Binding Image.Source from download memory)
- Silverlight 之 image source 绑定
- 稳扎稳打Silverlight(40) - 3.0绑定之Element to Element Binding, RelativeSource; 样式之动态修改样式, 样式继承, 自定义光标
- 稳扎稳打Silverlight(40) - 3.0绑定之Element to Element Binding, RelativeSource; 样式之动态修改样式, 样式继承, 自定义光标
- Silverlight BitmapImage的SetSource(Stream streamSource)致命性错误的解决办法
- Silverlight BitmapImage的SetSource(Stream streamSource)致命性错误的解决办法
- Silverlight BitmapImage的SetSource(Stream streamSource)致命性错误的解决办法
- [WP7]Silverlight: Creating a WriteableBitmap from a Uri Source
- BitmapImage.UriSource binding doesn't work ...
- Create an ISO Image from a source CD or DVD on ubuntu
- 数据绑定(六)使用XML数据作为Binding的Source
- 稳扎稳打Silverlight(50) - 4.0绑定之DependencyObject绑定, 索引器绑定, StringFormat, TargetNullValue和FallbackValue, CollectionViewSource
- 稳扎稳打Silverlight(50) - 4.0绑定之DependencyObject绑定, 索引器绑定, StringFormat, TargetNullValue和FallbackValue, CollectionViewSource
- 稳扎稳打Silverlight(50) - 4.0绑定之DependencyObject绑定, 索引器绑定, StringFormat, TargetNullValue和FallbackValue, CollectionViewSource
- 稳扎稳打Silverlight(50) - 4.0绑定之DependencyObject绑定, 索引器绑定, StringFormat, TargetNullValue和FallbackValue, CollectionViewSource
- Grid控件绑定bindingSource后在新增行时设置Cell的初始值
- silverlight中设置Image 的source
- DataSet / BindingSource / DataGridView / BindingNavigator 的关系与绑定、更新顺序
- Silverlight Image Source URI : 一个反斜杠引发的血案
- imagecreatefromjpegAllowed memory size of 13421772