LongListSelector和Image_MouseLeftButtonDown问题

时间:2014-04-20 02:44:19

标签: c# image windows-phone-8 longlistselector

如何管理事件LongListSelector_SelectionChanged先运行,然后运行Image_MouseLeftButtonDown

int count = 0;
Image LastImage = null, curImage = null;
BitmapImage bi1 = new BitmapImage();
BitmapImage bi2 = new BitmapImage();
int itemIndex;

void getImageLink()
{
  for (int i = 0; i < CImageControl.lstImage.Count; i++)
     s.Add(CImageControl.lstImage[i].ImageLink);
}

private void lstView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    var myItem = ((LongListSelector)sender).SelectedItem as CImage;
    itemIndex = ((LongListSelector)sender).ItemsSource.IndexOf(myItem);
    //MessageBox.Show(myIndex.ToString());
}

然后这将运行

private void Image_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    string lastImageSource, lastImageAltSource, curImageSource, curImageAltSource;
    count++;
    if (count % 2 != 0)
    {
        LastImage = (Image)sender;
        lastImageSource = s[itemIndex];
        lastImageAltSource = lastImage.Source.ToString();
    }
    else
    {
        curImage = (Image)sender;
        curImageSource = s[itemIndex];
        curImageAltSource = curImage.Source.ToString();
    }
}

ImageAltSouce是图片的显示,我想用ImageSource替换。但是在我可以更改任何源之前,我需要itemIndex在Longlistselector中查找图像索引。由于事件Image_MouseLeftButtonDown首先出现,所以我不能做任何事情

0 个答案:

没有答案