Guest User

AddEdit.cs

a guest
Sep 24th, 2013
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.85 KB | None | 0 0
  1. using DevExpress.Xpf.Mvvm;
  2. using MMHLive.Helpers;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Controls;
  10.  
  11. namespace MMHLive.ViewModels
  12. {
  13.     public class AddContainerVM : NavigationViewModelBase
  14.     {
  15.         private ObservableCollection<UserControl> views = new ObservableCollection<UserControl>();
  16.         public ObservableCollection<UserControl> Views
  17.         {
  18.             get { return views; }
  19.             set
  20.             {
  21.                 views = value;
  22.                 RaisePropertyChanged(() => Views);
  23.             }
  24.         }
  25.         private UserControl currentView = new UserControl();
  26.  
  27.         public UserControl CurrentView
  28.         {
  29.             get
  30.             {
  31.                 return currentView;
  32.             }
  33.             set
  34.             {
  35.                 if((currentView as IAdd) != null)
  36.                     (currentView as IAdd).IsSelected = false;
  37.                 currentView = value;
  38.                 (currentView as IAdd).IsSelected = true;
  39.                 RaisePropertyChanged(() => CurrentView);
  40.                 RaisePropertyChanged(() => States);
  41.             }
  42.         }
  43.  
  44.         public ObservableCollection<IAdd> States
  45.         {
  46.             get
  47.             {
  48.                 return new ObservableCollection<IAdd>(Views.Select(v =>
  49.                 {
  50.                     var temp = (v as IAdd);
  51.                     return new Add(){ Attempted = temp.Attempted, Field = temp.Field, IsSelected = temp.IsSelected, IsValid = temp.IsValid, Value = temp.Value };
  52.                 }));
  53.             }
  54.         }
  55.  
  56.         public AddContainerVM(ObservableCollection<UserControl> _views)
  57.         {
  58.             Views = _views;
  59.             CurrentView = Views.First();
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment