0

In my Windows Store app I use a GridView with an ItemClick event handler:

<GridView Grid.Column="0" Grid.Row="1"
  SelectionMode="None"
  IsItemClickEnabled="True"
  ItemClick="ClickOnItem">
</GridView>

The items are bound to the GridView with ItemsSource. Is there the possibility to remove the click event for single items which have been bound to the GridView?

Benny Code
  • 51,456
  • 28
  • 233
  • 198

1 Answers1

1

I am not sure how suitable this is for your scenario, but one way to do this is to just ignore the click event based on the item:

void ClickOnItem(object sender, ItemClickEventArgs e)
{
    var item = (SampleDataItem)e.ClickedItem;

    // ignore one specific item - here we use UniqueId, but it could be
    // any attribute...
    if (string.Compare(item.UniqueId, "Group-1-Item-1") == 0)
        return;

    // normal processing here...
    ...
 }

Update - to add a click event programmatically, you have to name your grid (x:Name line):

<GridView Grid.Column="0" Grid.Row="1"
    x:Name="myGridView"
    SelectionMode="None"
    IsItemClickEnabled="True"
    ItemClick="ClickOnItem">
</GridView>

and then in the code behind, add the handler in the constructor of the page:

public PageConstructor()
{
    this.InitializeComponent();
    myGridView.ItemClick += ClickOnItem;
}
chue x
  • 18,573
  • 7
  • 56
  • 70
  • 1
    @BennyNeugebauer - you can programmatically add the click handler to the grid itself, which will then handle the click events for each item. See my **Update** above. – chue x Mar 27 '13 at 00:45