Advertisement
mrlacey

SO15107864 MainPage.xaml.cs

Feb 27th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.19 KB | None | 0 0
  1.  
  2. namespace SO15107864
  3. {
  4.     using System.Collections.Generic;
  5.     using System.ComponentModel;
  6.     using System.Data.Linq.Mapping;
  7.     using System.Windows;
  8.  
  9.     using Microsoft.Phone.Controls;
  10.  
  11.     public partial class MainPage : PhoneApplicationPage
  12.     {
  13.  
  14.         public MainPage()
  15.         {
  16.             InitializeComponent();
  17.  
  18.             this.Loaded += PhoneApplicationPage_Loaded_1;
  19.         }
  20.  
  21.         private void PhoneApplicationPage_Loaded_1(object sender, RoutedEventArgs e)
  22.         {
  23.             var listnames = this.GetNames();
  24.             List<NameItems> nm = new List<NameItems>();
  25.  
  26.             foreach (Names mynames in listnames)
  27.             {
  28.                 var fname = mynames.F_Name;
  29.                 var lname = mynames.L_Name;
  30.  
  31.                 nm.Add(new NameItems { fname = fname, lname = lname });
  32.             }
  33.  
  34.             namelonglistselector.ItemsSource = nm;
  35.         }
  36.  
  37.         private IEnumerable<Names> GetNames()
  38.         {
  39.             yield return new Names { F_Id = 1, F_Name = "fname 1", L_Name = "lname1" };
  40.             yield return new Names { F_Id = 2, F_Name = "fname 2", L_Name = "lname2" };
  41.             yield return new Names { F_Id = 3, F_Name = "fname 3", L_Name = "lname3" };
  42.             yield return new Names { F_Id = 4, F_Name = "fname 4", L_Name = "lname4" };
  43.         }
  44.     }
  45.  
  46.     [Table]
  47.     public class Names : INotifyPropertyChanged, INotifyPropertyChanging
  48.     {
  49.         [Column(IsPrimaryKey = true, IsDbGenerated = true, CanBeNull = false, AutoSync = AutoSync.OnInsert)]
  50.         private int id;
  51.  
  52.         public int F_Id
  53.         {
  54.             get { return id; }
  55.             set
  56.             {
  57.                 NotifyPropertyChanging("F_Id");
  58.                 id = value;
  59.                 NotifyPropertyChanged("F_Id");
  60.             }
  61.         }
  62.  
  63.         [Column]
  64.         private string f_name;
  65.  
  66.         public string F_Name
  67.         {
  68.             get { return f_name; }
  69.             set
  70.             {
  71.                 NotifyPropertyChanging("F_Name");
  72.                 f_name = value;
  73.                 NotifyPropertyChanged("F_Name");
  74.             }
  75.         }
  76.  
  77.         [Column]
  78.         private string l_name;
  79.  
  80.         public string L_Name
  81.         {
  82.             get { return l_name; }
  83.             set
  84.             {
  85.                 NotifyPropertyChanging("L_Name");
  86.                 l_name = value;
  87.                 NotifyPropertyChanged("L_Name");
  88.             }
  89.         }
  90.  
  91.         public event PropertyChangedEventHandler PropertyChanged;
  92.  
  93.         private void NotifyPropertyChanged(string propertyName)
  94.         {
  95.             if (PropertyChanged != null)
  96.             {
  97.                 PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  98.             }
  99.         }
  100.  
  101.         public event PropertyChangingEventHandler PropertyChanging;
  102.  
  103.         private void NotifyPropertyChanging(string propertyName)
  104.         {
  105.             if (PropertyChanging != null)
  106.             {
  107.                 PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
  108.             }
  109.         }
  110.     }
  111.  
  112.     class NameItems
  113.     {
  114.         public string fname { get; set; }
  115.         public string lname { get; set; }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement