开发者

How To Display the Images Dynamically in windows phone 7 application developement?

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 dy开发者_如何学Cnamically in windows phone 7 using silverlight.


I know this is a very old question but I had a couple of free minutes ;)

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜