简体   繁体   English

如何确定选定的GridView项目?

[英]How to determine selected gridview item?

I have a gridView. 我有一个gridView。 instead of ItemTemplate I used user control for gridviewitems because I cant manage to trigger the button click event in the itemtemplate 代替ItemTemplate我将用户控件用于gridviewitems,因为我无法设法触发itemtemplate中的按钮单击事件

here is my code 这是我的代码

for (int i = 0; i < collection.Count(); i++)
{
     GridViewItem gridViewItem = new GridViewItem();
     gridViewItem.Tag = i;
     PhotoItem item = new PhotoItem();

     item.photoTitleTextBlock.Text = collection[i].Type.ToString();
     item.eraseButton.Click += (sender, args) => { itemSent(item); };

     gridViewItem.Content = item;
     gvIdTypes.Items.Add(gridViewItem);
}

in my userControl PhotoItem there are textblock, button and image textblock.text comes from collection if gridview item is selected(via gridView.selectionChanged event) web cam takes photo and puts on the image of the UserControl 在我的userControl PhotoItem中,有textblock,button和image textblock.text来自集合,如果选择了gridview项(通过gridView.selectionChanged事件),则网络摄像头拍照并放在UserControl的图像上

how can I figure out which of the item is selected in the selectionChanged event 如何确定在selectionChanged事件中选择了哪个项目

改用ItemClick ,然后您可以在ItemClickEventArgs访问ClickedItem

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM