public void Refresh(IBehaviorContext context, RefreshOptions options) { var collection = GetValue(context); Repopulate(context, collection, RefreshReason.Create(options.ExecuteRefreshDependencies)); this.RefreshNext(context, options); }
public void Refresh(IBehaviorContext context, RefreshOptions options) { // Call next behavior first, because a source accessor behavior may handle // it. this.RefreshNext(context, options); _collectionSourceCache.Clear(context); // ToArray so that (1) source is only enumerated once and (2) acess by index // (required by the equality check) is guaranteed to be fast. TItemSource[] newSourceItems = GetSourceItems(context).ToArray(); IVMCollection <TItemVM> vmCollection = GetValue(context); IEnumerable <TItemVM> itemsToRefresh = Enumerable.Empty <TItemVM>(); if (AreCollectionContentsEqual(vmCollection, newSourceItems)) { itemsToRefresh = vmCollection; } else { Dictionary <TItemSource, TItemVM> previousItemsBySource = vmCollection.ToDictionary( x => x.Source, _reusabilitySourceComparer ); List <TItemVM> newItems = new List <TItemVM>(); List <TItemVM> reusedItems = new List <TItemVM>(); foreach (TItemSource s in newSourceItems) { TItemVM item; bool isReusedItem = previousItemsBySource.TryGetValue(s, out item); if (isReusedItem) { reusedItems.Add(item); } else { item = CreateAndInitializeItem(context, s); } newItems.Add(item); } vmCollection.ReplaceItems(newItems, RefreshReason.Create(options.ExecuteRefreshDependencies)); itemsToRefresh = reusedItems; } if (options.Scope.HasFlag(RefreshScope.Content)) { itemsToRefresh .ForEach(x => x.Kernel.RefreshWithoutValidation(options.ExecuteRefreshDependencies)); } }
public void Refresh(IBehaviorContext context, RefreshOptions options) { RequireInitialized(); var previousValue = GetValue(context); RefreshCache(context); var newValue = GetValue(context); if (!Object.Equals(newValue, previousValue)) { var args = ChangeArgs.ViewModelPropertyChanged( _property, ValueStage.ValidatedValue, previousValue, newValue, RefreshReason.Create(options.ExecuteRefreshDependencies) ); context.NotifyChange(args); } this.RefreshNext(context, options); }
//internal IList<IPropertySelector> TargetProperties { // get { return _targetProperties; } //} public override void Execute( IViewModel ownerVM, ChangeArgs args, DeclarativeDependency dependency ) { RefreshReason reason = args.Reason as RefreshReason; if (reason != null && !reason.ExecuteRefreshDependencies) { return; } RefreshTrace.BeginRefresh(dependency); _target.ForeachLoadedDescendant(ownerVM, (vm, props) => { if (props.Any()) { // TODO: The logic with 'wouldRefreshChangeSource' is not correct. The refresh source // may be an descendant of 'vm' in which case it would nevertheless be refreshed. // Unit test 'SetValue_WhenValidationResultChanges_WorksWithSelfRecursiveDependency' // reproduces this. foreach (var prop in props) { bool wouldRefreshChangeSource = vm == args.ChangedVM && prop == args.ChangedProperty; if (!wouldRefreshChangeSource) { vm.Kernel.RefreshInternal(prop, new RefreshOptions(_executeRefreshDependencies)); } } } else { bool wouldRefreshChangeSource = vm == args.ChangedVM; if (!wouldRefreshChangeSource) { vm.Kernel.RefreshInternal(_executeRefreshDependencies); } } }); //_target.Refresh(ownerVM, _executeRefreshDependencies); //ownerVM.Kernel.RefreshInternal(_target, _executeRefreshDependencies); //if (TargetPath.IsEmpty) { // if (_targetProperties.Count > 0) { // RefreshProperties(ownerVM); // } else { // ownerVM.Kernel.RefreshInternal(_executeRefreshDependencies); // } //} else { // var viewModels = TargetPath.GetDescendants(ownerVM); // foreach (var viewModel in viewModels) { // if (_targetProperties.Count > 0) { // RefreshProperties(viewModel); // } else { // viewModel.Kernel.RefreshInternal(_executeRefreshDependencies); // } // } //} RefreshTrace.EndLastRefresh(); }