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:
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;
}
}
标签:
windows-phone-7