سؤال

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?

هل كانت مفيدة؟

المحلول

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;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top