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); }
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)); }
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); }
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); }
protected IEnumerable <T> GetCollection <T>(string propertyName, Func <IEnumerable <T> > getMethod) { ForView.Initialize(); return(_propertyTracker.GetCollection(getMethod, propertyName)); }
protected T Get <T>(string propertyName, Func <T> getMethod) { ForView.Initialize(); return(_propertyTracker.Get(getMethod, propertyName)); }