smeacham

ObservableItem.cs

Jun 3rd, 2016
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. using System.ComponentModel;
  8. using System.Runtime.CompilerServices;
  9.  
  10. namespace ListViewDemoVS
  11. {
  12.     class ObservableItem : INotifyPropertyChanged
  13.     {
  14.         public event PropertyChangedEventHandler PropertyChanged;
  15.         Item item;
  16.  
  17.         public ObservableItem()
  18.         {
  19.             item = new Item();
  20.         }
  21.  
  22.         public string Title
  23.         {
  24.             set
  25.             {
  26.                 if (!value.Equals(item.Title, StringComparison.Ordinal))
  27.                 {
  28.                     item.Title = value;
  29.                     OnPropertyChanged("Title");
  30.                 }
  31.             }
  32.             get
  33.             {
  34.                 return item.Title;
  35.             }
  36.         }
  37.  
  38.         public string Description
  39.         {
  40.             set
  41.             {
  42.                 if (!value.Equals(item.Description, StringComparison.Ordinal))
  43.                 {
  44.                     item.Description = value;
  45.                     OnPropertyChanged("Description");
  46.                 }
  47.             }
  48.             get
  49.             {
  50.                 return item.Description;
  51.             }
  52.         }
  53.  
  54.         void OnPropertyChanged([CallerMemberName] string propertyName = null)
  55.         {
  56.             var handler = PropertyChanged;
  57.             if (handler != null)
  58.             {
  59.                 handler(this, new PropertyChangedEventArgs(propertyName));
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment