Created
September 6, 2012 13:55
-
-
Save lambda125/3656495 to your computer and use it in GitHub Desktop.
GridView ItemClick handling
This file contains hidden or 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
<GridView ItemClick="OnDetailItemClick" | |
ItemsSource="{Binding RandomStrings}" /> |
This file contains hidden or 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
<GridView IsItemClickEnabled="True" | |
ItemClick="OnDetailItemClick" /> |
This file contains hidden or 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
<Page | |
x:Class="BlogSamples.MainPage" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
mc:Ignorable="d"> | |
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"> | |
<GridView x:Name="detailItemsView" | |
IsItemClickEnabled="True" | |
ItemClick="OnDetailItemClick" | |
ItemsSource="{Binding RandomStrings}" | |
SelectedItem="{Binding SelectedString}" | |
SelectionMode="Extended"> | |
</GridView> | |
</Grid> | |
</Page> |
This file contains hidden or 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
using BlogSamples.ViewModels; | |
using Windows.UI.Xaml.Controls; | |
namespace BlogSamples | |
{ | |
public sealed partial class MainPage : Page | |
{ | |
public MainPage() | |
{ | |
this.InitializeComponent(); | |
DataContext = new MainPageViewModel(); //ignoring IoC for now | |
} | |
private void OnDetailItemClick(object sender, ItemClickEventArgs e) | |
{ | |
var vm = (MainPageViewModel) DataContext; | |
vm.SelectedString = (string)e.ClickedItem; | |
} | |
} | |
} |
This file contains hidden or 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
using System.Collections.ObjectModel; | |
using System.ComponentModel; | |
namespace BlogSamples.ViewModels | |
{ | |
public class MainPageViewModel : INotifyPropertyChanged | |
{ | |
//... | |
public ObservableCollection<string> RandomStrings { get; private set; } | |
public string SelectedString | |
{ | |
// ... property impl not shown for brevity | |
} | |
public MainPageViewModel() | |
{ | |
RandomStrings = new ObservableCollection<string>(); | |
for (int i = 65; i < 98; i++) | |
{ | |
RandomStrings.Add(((char)i).ToString().ToUpper()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment