Advertisement
Guest User

ListPickerIssue

a guest
Jul 12th, 2012
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.25 KB | None | 0 0
  1. //XAML code
  2.  
  3. <toolkit:ListPicker x:Name="listPickerCountryLogin" Grid.Row="0" ExpansionMode="ExpansionAllowed" SelectionChanged="listPickerCountryLogin_SelectionChanged" HorizontalAlignment="Left" Margin="14,43,0,0" VerticalAlignment="Top" Width="436" FullModeHeader="Select Country" Background="White" BorderBrush="White">
  4.                 <toolkit:ListPicker.ItemTemplate>
  5.                     <DataTemplate>
  6.                         <StackPanel Orientation="Horizontal">
  7.                             <TextBlock Text="{Binding Country}" Width="250" />
  8.                         </StackPanel>
  9.                     </DataTemplate>
  10.                 </toolkit:ListPicker.ItemTemplate>
  11.                 <toolkit:ListPicker.FullModeItemTemplate>
  12.                     <DataTemplate>
  13.                         <StackPanel Orientation="Horizontal">
  14.                             <TextBlock Text="{Binding Country}" Width="300" Margin="0,0,0,20" FontSize="24"/>
  15.                         </StackPanel>
  16.                     </DataTemplate>
  17.                 </toolkit:ListPicker.FullModeItemTemplate>
  18.             </toolkit:ListPicker>
  19.  
  20.  
  21.             <toolkit:ListPicker x:Name="listPickerCCLogin" Grid.Row="1" ExpansionMode="FullScreenOnly" SelectionChanged="listPickerCCLogin_SelectionChanged" Width="80" HorizontalAlignment="Left" Margin="14,10,0,0"  VerticalAlignment="Top" FullModeHeader="Select Country" Background="White" BorderBrush="White">
  22.                 <toolkit:ListPicker.ItemTemplate>
  23.                     <DataTemplate>
  24.                         <StackPanel Orientation="Horizontal">
  25.                             <TextBlock Name="lblCC" Text="{Binding CC}" Width="235" />
  26.                         </StackPanel>
  27.                     </DataTemplate>
  28.                 </toolkit:ListPicker.ItemTemplate>
  29.                 <toolkit:ListPicker.FullModeItemTemplate>
  30.                     <DataTemplate>
  31.                         <StackPanel Orientation="Horizontal">
  32.                             <TextBlock  Text="{Binding Country}" Width="300" Margin="0,0,0,20" FontSize="24"/>
  33.                         </StackPanel>
  34.                     </DataTemplate>
  35.                 </toolkit:ListPicker.FullModeItemTemplate>
  36.             </toolkit:ListPicker>
  37.             <Button Content="change" Grid.Row="2"  Height="200" Click="Button_Click" BorderThickness="1" />
  38.  
  39.  
  40. //C# code
  41.  
  42. public MainPage()
  43. {
  44.  InitializeComponent();
  45.  List<Countries> source = new List<Countries>();
  46.  source.Add(new Cities() { Country = "ES", CC = "10" });
  47.  source.Add(new Cities() { Country = "US", CC = "20" });
  48.  source.Add(new Cities() { Country = "UK", CC = "30" });
  49.  source.Add(new Cities() { Country = "MX", CC = "40" });
  50.  
  51.  this.listPickerCountryLogin.ItemsSource = source;
  52.  this.listPickerCCLogin.ItemsSource = source;
  53. }
  54.  
  55. private void Button_Click(object sender, RoutedEventArgs e)
  56. {
  57.   WebClient client = new WebClient();
  58.   client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
  59.   client.DownloadStringAsync(new Uri("http://api.twitter.com/1/statuses/public_timeline.json", UriKind.Absolute));
  60. }
  61.  
  62. void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
  63. {
  64.     //var deserialized = JsonConvert.DeserializeObject(e.Result);
  65.     Dispatcher.BeginInvoke(new System.Action(delegate()
  66.     {
  67.           listPickerCountryLogin.SelectedIndex = 1;
  68.           listPickerCCLogin.SelectedIndex = 1;
  69.     }));
  70. }
  71.  
  72. private void listPickerCountryLogin_SelectionChanged(object sender, SelectionChangedEventArgs e)
  73. {
  74.        if (listPickerCountryLogin.SelectedIndex >= 0 && listPickerCountryLogin.SelectedIndex < listPickerCCLogin.Items.Count)
  75.           listPickerCCLogin.SelectedIndex = listPickerCountryLogin.SelectedIndex;
  76. }
  77.  
  78. private void listPickerCCLogin_SelectionChanged(object sender, SelectionChangedEventArgs e)
  79. {
  80.       if (listPickerCCLogin.SelectedIndex >= 0 && listPickerCCLogin.SelectedIndex < listPickerCountryLogin.Items.Count)
  81.          listPickerCountryLogin.SelectedIndex = listPickerCCLogin.SelectedIndex;
  82. }
  83.  
  84.  
  85. //And finally Countries class is:
  86.  
  87.  public class Countries
  88.     {
  89.         public string Country
  90.         {
  91.             get;
  92.             set;
  93.         }
  94.         public string CC
  95.         {
  96.             get;
  97.             set;
  98.         }
  99.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement