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; }
} }

最新文章

  1. [AngularJS] AngularJS系列(5) 中级篇之动画
  2. memcache 笔记
  3. Android 进程常驻----开机广播的简单守护以及总结
  4. Centos7安装配置NFS服务和挂载
  5. (DFS)hdoj1198-Farm Irrigation
  6. VC 宏与预处理使用方法总结
  7. .net web程序发布之后,出现编译错误
  8. Java常见知识问答
  9. ORACLE网络配置大全没有比这个更详细的【weber出品】
  10. projecteuler----&amp;gt;problem=14----Longest Collatz sequence
  11. PDE_DATA 定义
  12. gevent拾遗
  13. 使用秘钥连接ssh
  14. 【Android Studio安装部署系列】九、Android Studio常用配置以及快捷键
  15. IDEA编译器的常用快捷键
  16. ubuntu下安装pandas出现 compile failed with error code 1 in /tmp/pip_build_hadoop/pandas
  17. hadoop的job执行在yarn中内存分配调节————Container [pid=108284,containerID=container_e19_1533108188813_12125_01_000002] is running beyond virtual memory limits. Current usage: 653.1 MB of 2 GB physical memory used
  18. nginx配置集群
  19. jQuery事件--keypress([[data],fn])和trigger(type,[data])
  20. day 68 增删改查 语法

热门文章

  1. java-数据库连接工具类 DataSourceUtil.java
  2. BuddyPress创建组、查看成员信息等找不到页面
  3. 格林威治时间格式(GMT)与普通时间格式的互相转换
  4. Maven中央仓库——你可能不知道的细节
  5. 如果分配给命令的连接位于本地挂起事务中,ExecuteNonQuery 要求命令拥有事务。命令的 Transaction 属性尚未初始化
  6. JavaScript-事件冒泡简介及应用
  7. Oracle行列转换的思考与总结
  8. win7笔记本电脑怎么做wifi热点
  9. 面试题:谈谈如何优化MYSQL数据库查询
  10. Collabration Web Application Screenshot(English Language) Free download now!