Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel()
        {
            this.AddPlaceholderTabCommand = new RelayCommand(() => this.Tabs.Add(new PlaceholderTab(this)));

            PeopleViewModel peopleViewModel = new PeopleViewModel(this);

            this.Tabs = new ObservableCollection <TabViewModel>();
            this.Tabs.Add(peopleViewModel);
            this.Tabs.Add(new PlaceholderTab(this));
            this.Tabs.Add(new PlaceholderTab(this));

            //if (IsInDesignMode)
            //{
            //    // Code runs in Blend --> create design time data.
            //}
            //else
            //{
            //    // Code runs "for real"
            //}
        }
Ejemplo n.º 2
0
        public PersonViewModel(PeopleViewModel peopleViewModel)
        {
            if (peopleViewModel == null)
            {
                throw new ArgumentNullException("peopleViewModel");
            }

            this.PeopleViewModel = peopleViewModel;

            React.To(() => this.Age - PeopleViewModel.AverageAge)
            .Select(diff =>
            {
                if (diff > 0)
                {
                    return("above average");
                }
                else if (diff == 0)
                {
                    return("exact average");
                }
                else
                {
                    return("below average");
                }
            })
            .SetAndNotify(() => ComparedToAverageAge);

            //TODO: SetAndNotify usually has no equality check on the new value.
            //Put such logic in SetAndNotify itself.
            React.To(() => this.Age - PeopleViewModel.AverageAge)
            .Select(diff =>
            {
                if (diff > 0)
                {
                    return(new RotateTransform(-90.0));
                }
                else if (diff == 0)
                {
                    return(new RotateTransform(0.0));
                }
                else
                {
                    return(new RotateTransform(90.0));
                }
            })
            .SetAndNotify(() => ArrowIndicatorRotation);

            React.To(() => this.Age - PeopleViewModel.AverageAge)
            .Select(diff =>
            {
                if (diff > 0)
                {
                    return(Brushes.Green);
                }
                else if (diff == 0)
                {
                    return(Brushes.Blue);
                }
                else
                {
                    return(Brushes.Red);
                }
            })
            .SetAndNotify(() => ArrowIndicatorColor);
        }