如何在windows phone 7应用程序开发中动态显示图像?
问题描述:
我想动态显示图像.即,如果每次单击特定图像多次(4 到 5 次)可以消失并且新图像可以填充此位置.我想显示图像使用 Silverlight 在 Windows Phone 7 中动态显示.
I Want to Display the Images Dynamically.i'e If Whenever Click On Particular image some more (4 to 5 times)times that can be disappear and new image can be fill this place.in that i want to display the images dynamically in windows phone 7 using silverlight.
答
我知道这是一个很老的问题,但我有几分钟的空闲时间 ;)
每四次点击屏幕,下面将显示与设备上存储的图像不同的随机图像.
The following will display a different random image from the images stored on the device every fourth time the screen is tapped.
XAML:
xmlns:Controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.Background>
<ImageBrush x:Name="myImg" />
</Grid.Background>
<Controls:GestureService.GestureListener>
<Controls:GestureListener Tap="GestureListener_Tap" />
</Controls:GestureService.GestureListener>
</Grid>
C#
using Microsoft.Phone.Controls;
using System.Windows.Media.Imaging;
using Microsoft.Xna.Framework.Media;
private int tapCount = 0;
private void GestureListener_Tap(object sender, GestureEventArgs e)
{
tapCount += 1;
if (tapCount % 4 == 0)
{
SetRandomImage();
}
}
private void SetRandomImage()
{
var lib = new MediaLibrary();
using (var pic = lib.Pictures[new Random().Next(0, lib.Pictures.Count - 1)])
{
var img = new BitmapImage();
img.SetSource(pic.GetImage());
myImg.ImageSource = img;
}
}