Silverlight Load Client Image 加载客户端图片

简介: Silverlight Load Client Image 加载客户端图片 这里做了一个用Silverlight加载客户端图片的例子。并且用了一个最简单的数据双向绑定。 beginning 这里例子的代码很简单不用做太多的说明。

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:

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:

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

相关文章
|
定位技术 API
ArcGIS API for Silverlight加载google地图(后续篇)
之前在博客中(http://blog.csdn.net/taomanman/article/details/8019687)提到的加载google地图方案,因为google地址问题,看不到图了,发现是url地址变换造成的。
757 0
|
定位技术 API
ArcGIS API for Silverlight之配准JPG图片地图文字倾斜解决方案
根据实际JPG图片进行配准后,发布的地图,利用ArcGIS API for Silverlight在网页上显示的时候,原先的文字总有倾斜的现象,如何解决?   图一、配准后有文字倾斜现象的地...
899 0

热门文章

最新文章