/// <summary> /// Provides a values to be used by the framework to set a given target's object target property binding. /// </summary> /// <param name="serviceProvider">Service provider offered by the framework.</param> /// <returns>A <see cref="Binding"/> for the targeted object and property.</returns> public override object ProvideValue(IServiceProvider serviceProvider) { var result = base.ProvideValue(serviceProvider); // 'Normal' binding is no filter source type is provided: if (SourceType == null) { initialized = true; } // else process only if a binding was issued and source type is not set: else if (result is BindingExpression) { // Build self binding which will be our "null" value to set: selfPropertyBinding = BindingHelpers.GetIdentityBinding(TargetProperty); // Try init: Initialize(GetInnerBindingSource(serviceProvider)); if (!initialized || init_to_empty) { innerBinding = InnerBinding; // keep a copy for later usage. return(selfPropertyBinding.ProvideValue(serviceProvider)); // return empty binding we do not know source type or if inited as it. } } return(result); // return if full binding is required, or SharedDp or whatever was issued. }
/// <summary> /// Provides a values to be used by the framework to set a given target's object target property binding. /// </summary> /// <param name="serviceProvider">Service provider offered by the framework.</param> /// <returns>A <see cref="Binding"/> for the targeted object and property.</returns> public override object ProvideValue(IServiceProvider serviceProvider) { // Format will be: // <MyDependencyObject MyProperty={BoundPathBinding PathValueBinding={Binding somePropertyProvider}} /> // Build binding in base: var result = base.ProvideValue(serviceProvider); // 'Normal' binding is no path is provided: if (PathValueBinding == null) { initialized = true; } // Else try to setup binding from here (else will be redone at init and loading): else if (result is BindingExpression) { // As we won't return it as result to framework, it will be GCed. Keep a copy now: boundPathBinding = InnerBinding?.Clone(); if (boundPathBinding != null) { // Try to init now: providing_value = true; Initialize(serviceProvider); providing_value = false; // If success, then return bound path binding immediately: if (initialized) { return(boundPathBinding.ProvideValue(serviceProvider)); } else // Else return empty binding: { // Build self binding which will be our "null" value to set: selfPropertyBinding = BindingHelpers.GetIdentityBinding(TargetProperty); return(selfPropertyBinding.ProvideValue(serviceProvider)); // and return an empty binding while path is unresolved. } } else { initialized = true; } } return(result); }