Skip to content

Instantly share code, notes, and snippets.

@damirarh
Created June 23, 2013 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damirarh/5844561 to your computer and use it in GitHub Desktop.
Save damirarh/5844561 to your computer and use it in GitHub Desktop.
<ListView IsItemClickEnabled="True"
ItemsSource="{Binding Items}">
<i:Interaction.Behaviors>
<local:ItemClickedBehavior ItemClickedCommand="{Binding ItemClickedCommand}" />
</i:Interaction.Behaviors>
</ListView>
public class ItemClickedBehavior : Behavior<ListViewBase>
{
public static readonly DependencyProperty ItemClickedCommandProperty = DependencyProperty.Register(
"ItemClickedCommand",
typeof(ICommand),
typeof(ItemClickedBehavior),
new PropertyMetadata(null));
public ICommand ItemClickedCommand
{
get { return (ICommand)GetValue(ItemClickedCommandProperty); }
set { SetValue(ItemClickedCommandProperty, value); }
}
protected override void OnAttached()
{
base.OnAttached();
AssociatedObject.ItemClick += OnItemClick;
}
protected override void OnDetaching()
{
base.OnDetaching();
AssociatedObject.ItemClick -= OnItemClick;
}
private void OnItemClick(object sender, ItemClickEventArgs e)
{
ItemClickedCommand.Execute(e.ClickedItem);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment