This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

ComboBox XAML Issue Silverlight MVVM Extra Code

By: a guest on Aug 15th, 2011  |  syntax: C#  |  size: 2.23 KB  |  views: 87  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class MainPageViewModel : ViewModelBase
  2. {
  3.     private ObservableCollection<Company> _Companies;
  4.     private Company _CurrentCompany;
  5.  
  6.     /* ... */
  7.  
  8.     public ObservableCollection<Company> CompanyList
  9.     {
  10.         get
  11.         {
  12.             return _Companies;
  13.         }
  14.  
  15.         set
  16.         {
  17.             if (_Companies != value)
  18.             {
  19.                 _Companies = value;
  20.                 OnPropertyChanged("CompanyList");
  21.             }
  22.         }
  23.     }
  24.  
  25.     public Company CurrentCompany
  26.     {
  27.         get
  28.         {
  29.             return _CurrentCompany;
  30.         }
  31.  
  32.         set
  33.         {
  34.             if (_CurrentCompany != value)
  35.             {
  36.                 _CurrentCompany = value;
  37.                 OnPropertyChanged("CurrentCompany");
  38.             }
  39.         }
  40.     }
  41. }
  42. public abstract class ViewModelBase : INotifyPropertyChanged
  43. {
  44.     public bool IsDesignTime
  45.     {
  46.         get { return DesignerProperties.IsInDesignTool; }
  47.     }
  48.  
  49.     public event PropertyChangedEventHandler PropertyChanged;
  50.  
  51.     protected virtual void OnPropertyChanged(string propName)
  52.     {
  53.         var propChanged = PropertyChanged;
  54.         if (propChanged != null)
  55.         {
  56.             propChanged(this, new PropertyChangedEventArgs(propName));
  57.         }
  58.     }
  59. }
  60.    
  61. public class Company : INotifyPropertyChanged
  62. {
  63.     public string Name { get; set; }
  64.     public string Value { get; set; }
  65.  
  66.     public Company(string name, string value)
  67.     {
  68.         Name = name;
  69.         Value = value;
  70.     }
  71.    
  72.     protected virtual void OnPropertyChanged(String propertyName)
  73.     {
  74.         if (_propertyChanged != null)
  75.         {
  76.             _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
  77.         }
  78.     }
  79.  
  80.     protected virtual void OnNavigationPropertyChanged(String propertyName)
  81.     {
  82.         if (_propertyChanged != null)
  83.         {
  84.             _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
  85.         }
  86.     }
  87.  
  88.     event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged { add { _propertyChanged += value; } remove { _propertyChanged -= value; } }
  89.     private event PropertyChangedEventHandler _propertyChanged;
  90.     private ObjectChangeTracker _changeTracker;
  91. }
clone this paste RAW Paste Data