Ejemplo n.º 1
0
        protected override void OnDetaching()
        {
            foreach (VisualStateSwitch binding in this)
            {
                binding.Detach();
            }

            valueSourceBindingObserver = null;
        }
Ejemplo n.º 2
0
        private void CreateValueSourceBindingObserver()
        {
            if (valueSourceBindingObserver != null)
            {
                valueSourceBindingObserver.ValueChanged -= OnValueSourceValueChanged;
            }

            valueSourceBindingObserver = new BindingObserver
            {
                DataContext = DataContext
            };
            valueSourceBindingObserver.ValueChanged += OnValueSourceValueChanged;
            valueSourceBindingObserver.SetBinding(BindingObserver.ValueProperty, ValueSource);
        }
Ejemplo n.º 3
0
        /// <summary>Disables the <see cref="T:Microsoft.OData.Client.DataServiceContext" /> tracking of all items in the collection.</summary>
        /// <remarks>
        /// All the entitities in the root collection and all it's related objects will be untracked at the
        /// end of this operation.
        /// </remarks>
        public void Detach()
        {
            if (!this.IsTracking)
            {
                throw new InvalidOperationException(Strings.DataServiceCollection_OperationForTrackedOnly);
            }

            // Operation only allowed on root collections.
            if (!this.rootCollection)
            {
                throw new InvalidOperationException(Strings.DataServiceCollection_CannotStopTrackingChildCollection);
            }

            this.observer.StopTracking();
            this.observer = null;

            this.rootCollection = false;
        }
Ejemplo n.º 4
0
        /// <summary>Initialize and start tracking an DataServiceCollection</summary>
        /// <param name="context">The context</param>
        /// <param name="items">Collection to initialize with</param>
        /// <param name="entitySet">The entity set of the elements in the collection.</param>
        /// <param name="entityChanged">delegate that needs to be called when an entity changes.</param>
        /// <param name="collectionChanged">delegate that needs to be called when an entity collection is changed.</param>
        private void StartTracking(
            DataServiceContext context,
            IEnumerable <T> items,
            String entitySet,
            Func <EntityChangedParams, bool> entityChanged,
            Func <EntityCollectionChangedParams, bool> collectionChanged)
        {
            Debug.Assert(context != null, "Must have a valid context to initialize.");
            Debug.Assert(this.observer == null, "Must have no observer which implies Initialize should only be called once.");

            context.UsingDataServiceCollection = true;

            // Verify that T corresponds to an entity type.
            // Validate here before any items are added to the collection because if this fails we want to prevent the collection from being populated.
            if (!BindingEntityInfo.IsEntityType(typeof(T), context.Model))
            {
                throw new ArgumentException(Strings.DataBinding_DataServiceCollectionArgumentMustHaveEntityType(typeof(T)));
            }

            // Set up the observer first because we want the collection to know it's supposed to be tracked while the items are being loaded.
            // Items being added to the collection are not added to the binding graph until later when StartTracking is called on the observer.
            this.observer = new BindingObserver(context, entityChanged, collectionChanged);

            // Add everything from the input collection.
            if (items != null)
            {
                try
                {
                    this.InternalLoadCollection(items);
                }
                catch
                {
                    // If any failures occur, reset the observer since we couldn't successfully start tracking
                    this.observer = null;
                    throw;
                }
            }

            this.observer.StartTracking(this, entitySet);

            this.rootCollection = true;
        }