Created
June 18, 2014 02:16
-
-
Save benhysell/b5bc7d5ba77ee0736c26 to your computer and use it in GitHub Desktop.
mvvmcross winphone bind item to viewmodel command
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
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); | |
} |
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
<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