Question

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?

Was it helpful?

Solution

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top