2017-01-10 7 views
1

コードビハインドで作成した子オブジェクトにクリックイベントを追加するにはどうすればよいですか?C#グリッドチャイルドにクリックイベントを追加

String[] imageNames = System.IO.Directory.GetFiles("Assets/Images/Gallery"); 

foreach (String image in imageNames) 
{ 
    Uri source = new Uri("ms-appx:///" + image); 

    ImageSource imgSource = new BitmapImage(source); 

    Image myImage = new Image(); 
    myImage.Source = imgSource; 

    gallery.Children.Add(myImage);  
} 

上記のコードは、galleryフォルダからすべての画像を取得し、それをvariablesizedwrapgridに追加します。私は

おかげ

答えて

1

1)

myImage.PointerReleased += Img_PointerReleased; 

private void Img_PointerReleased(object sender, PointerRoutedEventArgs e) 
{ 
    // do your job 
} 

2)(基本的に、ユーザは、彼らが使用しているデバイスに保存できるようにするために)これらの各上のクリックイベントを追加したいまたはUserControlを書きますデフォルトのボタンアニメーションを使用したくない場合は、Buttonから継承し、適切なVisualStatesを追加するイメージをラップする - この方法で、Clickedイベントを使用できるようになります

関連する問題