2010-07-13 100 views

回答

5

我知道這是一個非常古老的問題,但我有一對夫婦的免費分鐘;)

將顯示來自存儲在設備上每第四次的圖像不同的隨機圖像下點擊屏幕。

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; 
    } 
} 
相關問題