前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Silverlight Load Client Image 加载客户端图片

Silverlight Load Client Image 加载客户端图片

作者头像
用户1172164
发布2018-03-01 15:45:01
6730
发布2018-03-01 15:45:01
举报

Silverlight Load Client Image 加载客户端图片

这里做了一个用Silverlight加载客户端图片的例子。并且用了一个最简单的数据双向绑定。

beginning

这里例子的代码很简单不用做太多的说明。

前端界面设计

XAML:

<UserControl x:Class="LoadClientImage.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="400" Height="300" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Loaded="UserControl_Loaded"> <Grid x:Name="LayoutRoot" Background="White" Margin="3" > <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <Button HorizontalAlignment="Right" VerticalAlignment="Center" d:LayoutOverrides="Width"> <StackPanel Height="Auto" Width="Auto" Orientation="Horizontal"> <Image Source="pixelicious_112.png" Stretch="None"/> <TextBlock VerticalAlignment="Center" Text="加载图片" TextWrapping="Wrap"/> </StackPanel> </Button> <TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" Text="状态:" TextWrapping="Wrap" Margin="8,8,0,0"/> <TextBlock VerticalAlignment="Top" Text="{Binding Path=Status,Mode=TwoWay}" TextWrapping="Wrap" Margin="45,8,78,0"/> <Image Margin="3" x:Name="ImageHolder" Grid.ColumnSpan="2" Grid.Row="1" Grid.Column="0" Stretch="UniformToFill" /> </Grid> </UserControl>

定义页面数据模型

pageModel:

代码语言:js
复制
     public class pageModel : INotifyPropertyChanged {
 
 
 
 
         private string _status = "等待加载";
         public string Status
         {
             get { return _status; }
             set
             {
                 _status = value;
                 PropertyChanged(this, new PropertyChangedEventArgs("Status"));
             }
         }
 
 
         private BitmapImage _imageSource = new BitmapImage();
         public BitmapImage ImageSource {
             get { return _imageSource; }
             set
             {
                 _imageSource = value;
                 PropertyChanged(this, new PropertyChangedEventArgs("ImageSource"));
             }
         }
 
 
         #region INotifyPropertyChanged Members
 
 
         public event PropertyChangedEventHandler PropertyChanged;
 
 
         #endregion
     }
 

后台逻辑代码

Page:

代码语言:js
复制
 public partial class Page : UserControl
     {
         public pageModel model = new pageModel();
         public Page()
         {
             InitializeComponent();
         }
 
 
         private void UserControl_Loaded(object sender, RoutedEventArgs e)
         {
             this.DataContext = model;
         }
 
 
         private void Button_Click(object sender, RoutedEventArgs e)
         {
             OpenFileDialog ofd = new OpenFileDialog();
             ofd.Multiselect = false;
             bool? result = ofd.ShowDialog();
             if (!result.HasValue || result.Value == false)
                 return;
 
 
             BitmapImage imageSource = new BitmapImage();
             try
             {
                 imageSource.SetSource(ofd.File.OpenRead());
                 model.ImageSource = imageSource;
                 model.Status = "加载 " + ofd.File.Name + " 成功";
             }
             catch (Exception)
             {
                 model.Status = "加载失败";
             }
         }
 

提示: 不要忘记引入“BitmapImage”的命名空间:System.Windows.Media.Imaging;

Source

http://cid-3e15d91acc4385a8.skydrive.live.com/embedrowdetail.aspx/Project/LoadClientImage

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2009-01-15 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Silverlight Load Client Image 加载客户端图片
    • beginning
      • Source
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档