Extending GridView and Invoking ItemClick RRS feed

  • Question

  • Hey there,

    I'm trying to extend GridView so that I can get ItemContainerStyleSelector working. I've overridden PrepeareContainerItemOverride and its working, but it kills the ItemClick on the GridView. So I'm try to set route the Item's tapped event to the ItemClick handler, but I'm not sure how to do it. Here's my code:

    void CustomGridView::PrepareContainerForItemOverride(Windows::UI::Xaml::DependencyObject^ element, Platform::Object^ item)
    	auto elem = safe_cast<GridViewItem^>(element);
    	elem->Content = item;
    	if (ItemTemplate)
    		elem->ContentTemplate = ItemTemplate;
    	else if (ItemTemplateSelector)
    		elem->ContentTemplate = ItemTemplateSelector->SelectTemplate(item, element);
    	if (ItemContainerStyle)
    		elem->Style = ItemContainerStyle;
    	else if (ItemContainerStyleSelector)
    		elem->Style = ItemContainerStyleSelector->SelectStyle(item, element);
    	elem->IsTapEnabled = IsItemClickEnabled;
    	elem->Tapped += ref new TappedEventHandler(this, &CustomGridView::onItemTapped);
    void CustomGridView::onItemTapped(Object^ sender, TappedRoutedEventArgs^ e)
    	//Throws compiler error ('event does not have a raise method'):
    	ItemClick(this, ref new ItemClickEventArgs());

    Mark Rideout suggested using __super::PrepareContainerForItemOverride(element, item); but it goes into a recursive loop as I suggested in this post:


    Any help would be greatly appreciated.


    Monday, May 28, 2012 3:22 PM

All replies

  • I gave up trying to make this work properly. Microsoft has very conveniently locked everything down and made it private. I ended up adding my own event, ItemTapped, and delegate, item TappedEventHandler, which mimics ItemClick's behaviour by funnelling the items' events over. Sad, right?

    Monday, May 28, 2012 5:57 PM
  • Hello,


    Thanks for your feedback, I will involve more experts to investigate it.


    Best regards,


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, May 29, 2012 2:45 AM