a)簡單的方法是簡單地處理縮略圖的ManipulationStarted方法並將該縮略圖設置爲當前縮略圖。另外,處理較大照片的ManipulationStarted方法並檢查是否存在current thumbnail
。如果是這樣,請將較大照片的圖片來源設置爲縮略圖流的來源。
b)如果您需要透明度,您將不得不使用PNG。如果您不需要透明度,請使用JPG(提高效率)。
c)將縮略圖的圖像源設置爲null
以清除它。
編輯 - 這是做你想做的一種方式。當然,您可能想要使用UserControls,而不是單個圖像。
//class level variable that holds your current selected image
BitmapImage currentBitmap;
//Create an event handler to know when your page is loaded
public MyImagePage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MyImagePage_Loaded);
}
//Handle your Page Loaded event
void MyImagePage_Loaded(object sender, RoutedEventArgs e)
{
//Assign your thumbnail image control a picture
imgThumbnail.Source = new BitmapImage(new Uri("thumbnail.jpg", UriKind.Relative));
//Assign your large photo a default image (without an image, Manipulation methods won't be detected)
imgLarge.Source = new BitmapImage(new Uri("largeImage.jpg", UriKind.Relative));
//Make the current bitmap null
currentBitmap = null;
}
//Handle the ManipulationStarted event for your thumbnail image
private void imgThumbnail_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
//Set the currentImage to be that of the thumbnail
currentImage = (BitmapImage)imgThumbnail.Source;
}
//Handle the ManipulationStarted event for your large image
private void imgLarge_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
//check if the current image is null. If it's not, set the source for the large image
//to be that of the current image
if (currentImage != null)
imgLarge.Source = currentImage;
}
這是它背後的基礎知識。您可以創建一個類/ UserControl來代替具有指向圖像較大版本的屬性的縮略圖。然後,您可以將imgLarge
源設置爲該圖像較大版本的源。
希望有所幫助。
謝謝你。如果你能給我看一些代碼,請多多諒解。這項任務似乎涉及很多事情。 – MilkBottle 2011-06-02 05:24:18
@MilkBottle - 我已經添加了一些代碼,應該有助於讓事情變得更加清晰:) – keyboardP 2011-06-02 15:33:14