Created
June 23, 2013 10:36
-
-
Save damirarh/5844561 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ListView IsItemClickEnabled="True" | |
ItemsSource="{Binding Items}"> | |
<i:Interaction.Behaviors> | |
<local:ItemClickedBehavior ItemClickedCommand="{Binding ItemClickedCommand}" /> | |
</i:Interaction.Behaviors> | |
</ListView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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