public object ViewModel(Func <object> constructor)
        {
            if (DesignMode)
            {
                return(constructor());
            }

            string caller = new StackFrame(1).GetMethod().Name;

            if (!caller.StartsWith("get_"))
            {
                throw new ArgumentException("Only call ViewModel from a property getter.");
            }
            string propertyName = caller.Substring(4);

            ForView.Initialize();
            ViewModelContainer container;

            if (!_containerByName.TryGetValue(propertyName, out container))
            {
                container = new ViewModelContainer(() => FirePropertyChanged(propertyName), constructor);
                _containerByName.Add(propertyName, container);
            }
            return(container.ViewModel);
        }
Пример #2
0
        protected IEnumerable <T> GetCollection <T>(Func <IEnumerable <T> > getMethod)
        {
            ForView.Initialize();
            string caller = new StackFrame(1).GetMethod().Name;

            if (!caller.StartsWith("get_"))
            {
                throw new ArgumentException("Only call Get from a property getter.");
            }
            return(GetCollection <T>(caller.Substring(4), getMethod));
        }
Пример #3
0
        protected IEnumerable <T> GetCollection <T>(string propertyName, Func <IEnumerable <T> > getMethod)
        {
            ForView.Initialize();
            ComputedPropertyBase property;

            if (!_computedPropertyByName.TryGetValue(propertyName, out property))
            {
                property = new ComputedCollection <T>(getMethod);
                _computedPropertyByName.Add(propertyName, property);
            }
            return((IEnumerable <T>)property.Value);
        }
Пример #4
0
        protected T Get <T>(string propertyName, Func <T> getMethod)
        {
            ForView.Initialize();
            ComputedPropertyBase property;

            if (!_computedPropertyByName.TryGetValue(propertyName, out property))
            {
                property = new ComputedAtom <T>(() => FirePropertyChanged(propertyName), getMethod);
                _computedPropertyByName.Add(propertyName, property);
            }
            return((T)property.Value);
        }
 public ViewModelContainer(Action firePropertyChanged, Func <object> constructor)
 {
     _firePropertyChanged   = firePropertyChanged;
     _computed              = new Computed(() => _viewModel = ForView.Wrap(constructor()));
     _computed.Invalidated += () => UpdateScheduler.ScheduleUpdate(UpdateNow);
 }
Пример #6
0
 protected IEnumerable <T> GetCollection <T>(string propertyName, Func <IEnumerable <T> > getMethod)
 {
     ForView.Initialize();
     return(_propertyTracker.GetCollection(getMethod, propertyName));
 }
Пример #7
0
 protected T Get <T>(string propertyName, Func <T> getMethod)
 {
     ForView.Initialize();
     return(_propertyTracker.Get(getMethod, propertyName));
 }