Skip to content

Instantly share code, notes, and snippets.

@benhysell
Created June 18, 2014 02:16
Show Gist options
  • Save benhysell/b5bc7d5ba77ee0736c26 to your computer and use it in GitHub Desktop.
Save benhysell/b5bc7d5ba77ee0736c26 to your computer and use it in GitHub Desktop.
mvvmcross winphone bind item to viewmodel command
private void UIElement_OnTap(object sender, GestureEventArgs e)
{
var selectedItem = ((HomeViewModel) ViewModel).MenuItems.FirstOrDefault(x => x.Title == ((TextBlock)sender).Text);
if(null != selectedItem)
((HomeViewModel)ViewModel).SelectMenuItemCommand.Execute(selectedItem);
}
<ListBox
ItemsSource="{Binding MenuItems}" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="24">
<TextBlock Text="{Binding Title}" Tap="UIElement_OnTap" Style="{StaticResource PhoneTextTitle1Style}"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment