如何在windows phone 7应用程序开发中动态显示图像? [英] How To Display the Images Dynamically in windows phone 7 application developement?

查看:33
本文介绍了如何在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;
    }
}

这篇关于如何在windows phone 7应用程序开发中动态显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆