Windows Phone 在读取网络图片之前先显示默认图片
1.新建一个控件WindowsPhoneControl1
WindowsPhoneControl1.xaml
<UserControl x:Class="DefaultImage.WindowsPhoneControl1"
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"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="" d:DesignWidth=""> <Grid x:Name="LayoutRoot">
<Image Height="" HorizontalAlignment="Left" Margin="10,10,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="" Source="/DefaultImage;component/hotelphoto_alterimg.png" />
</Grid>
</UserControl>
WindowsPhoneControl1.cs
using System;
using System.Collections.Generic;
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;
using System.Windows.Threading;
using System.Windows.Media.Imaging; namespace DefaultImage
{
public partial class WindowsPhoneControl1 : UserControl
{
public WindowsPhoneControl1()
{
InitializeComponent();
DispatcherTimer timer = new DispatcherTimer();
timer.Tick += new EventHandler(timer_Tick);
timer.Interval = new TimeSpan(, , , , );
timer.Start();
} private string myImageSource;
public string MyImageSource
{
get
{
return myImageSource;
}
set
{
myImageSource = value;
WebClient wc = new WebClient();
wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
wc.OpenReadAsync(new Uri(myImageSource));
}
} void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(e.Result);
image1.Source = bitmapImage;
} void timer_Tick(object sender, EventArgs e)
{
MyImageSource = this.DataContext.ToString();
}
}
}
MainPage.xaml
<phone:PhoneApplicationPage
x:Class="DefaultImage.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="" d:DesignHeight=""
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True" xmlns:my="clr-namespace:DefaultImage"> <!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions> <!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel> <!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="" Margin="12,0,12,0">
<ListBox Height="" HorizontalAlignment="Left" ItemsSource="{Binding}" Margin="10,10,0,0" Name="listBox1" VerticalAlignment="Top" Width="">
<ListBox.ItemTemplate>
<DataTemplate>
<my:WindowsPhoneControl1 DataContext="{Binding MySource}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
</phone:PhoneApplicationPage>
MainPage.cs
using System;
using System.Collections.Generic;
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;
using Microsoft.Phone.Controls; namespace DefaultImage
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
var list = new List<MyImage> {
new MyImage(){ MySource= "http://i.microsoft.com/global/ImageStore/PublishingImages/Asset/thumbnails/icon_monthsecurityupdates_40x40.png"},
//new MyImage(){ MySource= "http://i.microsoft.com/global/ImageStore/PublishingImages/Asset/thumbnails/icon_mssecurityessentials_40x40.png"}
};
listBox1.DataContext = list;
}
}
public class MyImage
{
public string MySource { get; set; }
} }
Windows Phone 在读取网络图片之前先显示默认图片的更多相关文章
- Jquery判断页面图片是否加载失败,加载失败则显示默认图片
例子: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3. ...
- img如果没有图片显示默认图片效果
img如果没有图片显示默认图片效果<img src="本来要显示的图片URL" onerror="this.src='图片挂了的话要显示的默认图片URL'" ...
- JS检查当图片不存在时显示默认图片和键盘大小写键状态
当图片不存在时显示默认图片 <script type="text/javascript"> var imgs = document.images; for(var i ...
- vue中的图片加载与显示默认图片
HTML: <div class="content-show-img"> <div class="show-img"> <img ...
- 在HTML中显示图片时希望如果图片不存在或者无法显示时,能够显示默认图片
很多时候,在HTML中显示图片时希望如果图片不存在或者无法显示时,能够显示默认图片.可以通过以下方式: <img src="xxx.jpg" onError="th ...
- img 加载网络图片失败 显示默认图片
1. 概述 当从网络加载图片失败 希望显示默认图 img 标签有个 onerror属性 2. 代码 2.1 java服务端组织标签整个返回前端 String imgUrl = "javasc ...
- js处理img标签加载图片失败,显示默认图片
1.第一种方法: 如果已经引入了jquery插件,就很好办.没有的话,如果实在需要,可以附上代码: script(type='text/javascript', src="http://aj ...
- ionic 图片加载失败,显示默认图片代替
1.首先编写自定义指令 angular.module('starter.directives', []) //当图片找不到事显示替代图片 .directive("errSrc", ...
- js解决img标签加载失败显示默认图片
问题: 为所有显示楼盘的页面添加一个加载失败的默认图片. 基本思路: img标签中有个onerror属性,专门用来处理加载失败的事件.所以可以用jquery添加onerror属性,在onerror中加 ...
随机推荐
- DataRowState、AcceptChanges、RejectChanges综合使用示例:实现DataGridView数据的增、删、改
下面的示例中,通过一个程序,演示使用DataRowState.AcceptChanges.RejectChanges,实现DataGridView数据的增.删.改. 一.界面设计 二.代码实现 usi ...
- Cracking the coding interview--Q3.1
题目 原文: Describe how you could use a single array to implement three stacks. 译文: 你如何只用一个数组实现三个栈? 解答 我 ...
- node-webkit连接mysql
一.安装node.js mysql驱动库 node-webkit里面没有mysql模块的,我们需要安装mysql模块.我们可以使用npm(Node package manager)进行安装.这里使用到 ...
- chrome 如何利用快捷键将光标移动到地址栏
Windows: Ctrl + L 或 Alt + D 或 F6 Mac: Command + LLinux: Ctrl + L
- Hibernate关系映射 一对一双向外键关联@OneToOne Annotation方式 双向关联和单向关联的区别
首先还是来构造一个实际应用的场景,比如实体类车辆(Car),它具有以下属性:Id,品牌(brand),车牌(lisencePlate):实体类车牌(LisencePlate),它具有以下属性:Id,号 ...
- windows 批处理文件中引用日期
参见:http://blog.csdn.net/iw1210/article/details/39313677 %DATE%输出的是: yyyy/mm/dd 星期* (例如:2008/12/18 星期 ...
- 从零开始,制定PHP学习计划
7月份学习计划1-15 搭建开发环境.做个小demo 增删改查.Mysql数据库16-30号 架构设计.服务器管理.版本控制 8月份正式入手项目jquery脚本学习Thinksns开源学习.核心业务学 ...
- js学习之--Bootstrap Modals(模态框)
http://www.runoob.com/bootstrap/bootstrap-v2-modal-plugin.html http://outofmemory.cn/bootstrap/tutor ...
- Supervision 行为模式
官方链接:http://erlang.org/doc/man/supervisor.html http://erlang.org/doc/design_principles/sup_princ.htm ...
- 关于quartus ii软件中注释乱码问题的解决方法
乱码现象: 解决办法: 打开文件所在工程找到该verilog文件(后缀名是.v),使用记事本打开,这时你会看到注释好好的没乱码,很高兴是不,不用着急.接下来点击文件再另存为,选择编码:UTF-8,点保 ...