How to create event for lisview itemclik?

Oct 8, 2012 at 5:51 AM

Hi Andy

I am using Okra framework in my app,I am able to show data in listview using this framework.But i want to use this framework for item click event, and based on paramater i will show another page.

I found one article on google they are creating behavoiurs,see below content

<ListView x:Name="lstModules"
      Padding="10,0,0,60"
      IsItemClickEnabled="true"
      ItemsSource="{Binding Modules}">
   <interactivity:Interaction.Triggers>
      <interactivity:EventTrigger EventName="ItemClick">
          <julmar:InvokeCommand Command="{Binding SelectModule}" CommandParameter="{Binding ElementName=lstModules,Path=SelectedItem}" />
      </interactivity:EventTrigger>
   </interactivity:Interaction.Triggers>
How i do that using okra framework?
Coordinator
Oct 8, 2012 at 11:51 AM

Hi,

When using the Okra App Framework there are two approaches that I would suggest,

  • Firstly you could use one of the ports of the behaviours framework (such as https://github.com/jlaanstra/Windows.UI.Interactivity) and use this as above.
  • Alternatively (and the route I have been using in my own projects) you can add the 'ItemClick' event handler in the code-behind. Then you can cast the page's DataContext to your view-model type and call a method on the VM (passing in the clicked item). Not quite as neat a solution but works well.

Hope this helps,

    Andy

Coordinator
Oct 8, 2012 at 7:45 PM

As an example, if you are clicking on a Photo in a list on your home page you would write the ItemClick event in the code behind as,

private void photoListView_ItemClick(object sender, ItemClickEventArgs e)
{
    if (DataContext is HomeViewModel)
    {
        Photo photo = e.ClickedItem as Photo;
        HomeViewModel viewModel = (HomeViewModel)DataContext;
        viewModel.ViewPhoto(photo);
    }
}

Andy