How To Display the Images Dynamically in windows p

2020-06-22 06:04发布

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.

1条回答
We Are One
2楼-- · 2020-06-22 06:31

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;
    }
}
查看更多
登录 后发表回答