private bool TryGetPropItemParent ( WeakReference <PSAccessServiceInternalInterface> propStoreAccessService_Internal_wr, PropNode sourcePropNode, out WeakRefKey <IPropBag> propItemParentPropBag_wr ) { if (propStoreAccessService_Internal_wr.TryGetTarget(out PSAccessServiceInternalInterface storeAcessor_internal)) { if (storeAcessor_internal.TryGetParentPropBagProxy(sourcePropNode, out propItemParentPropBag_wr)) { return(true); } else { propItemParentPropBag_wr = new WeakRefKey <IPropBag>(null); return(false); } //WeakReference<IPropBagInternal> propItemParentPropBag_internal_wr = storeAcessor_internal.GetPropBagProxy(sourcePropNode); //WeakReference<IPropBag> propItemParentPropBag_wr = storeAcessor_internal.GetPublicInterface(propItemParentPropBag_internal_wr); //return propItemParentPropBag_wr; } else { propItemParentPropBag_wr = new WeakRefKey <IPropBag>(null); return(false); } }
private void PropertyChangedWithTVals_Handler(object sender, PcTypedEventArgs <T> e) { //System.Diagnostics.Debug.Assert(e.PropertyName == this.PropertyName, "PropertyName from PCTypedEventArgs does not match the PropertyName registered with the Binding."); System.Diagnostics.Debug.WriteLine("The terminal node's property value has been updated."); //CheckSenderAndOriginalSender(sender); switch (_notificationKind) { case PropStoreNotificationKindEnum.PropBag: { WeakRefKey <IPropBag> propItemParent = (sender as ObservableSource <T>).LastEventSender; NotifyReceiver(_storeNodeUpdateReceiver_PropBag, propItemParent); break; } case PropStoreNotificationKindEnum.PropNode: { // _sourcePropNode is set to the StorePropNode of the binding source as soon as the binding source has been reached. NotifyReceiver(_storeNodeUpdateReceiver_PropNode, _sourcePropNode, e); break; } case PropStoreNotificationKindEnum.Value: { NotifyReceiver(_storeNodeUpdateReceiver_Value, e); break; } default: { throw new InvalidOperationException($"The PropStoreNotificationKind of {_notificationKind} is not supported or is not recognized."); } } }
private bool UpdateTarget(WeakRefKey <IPropBag> bindingTarget, T newValue) { if (bindingTarget.TryGetTarget(out IPropBag propBag)) { bool wasSet; switch (_targetStorageStrategy) { case PropStorageStrategyEnum.Internal: wasSet = (propBag).SetIt(newValue, this.PropertyName); break; case PropStorageStrategyEnum.External: goto case PropStorageStrategyEnum.Virtual; case PropStorageStrategyEnum.Virtual: T dummy = default(T); wasSet = (propBag).SetIt(newValue, ref dummy, this.PropertyName); break; default: throw new InvalidOperationException($"{_targetStorageStrategy} is not a recognized or supported Prop Storage Strategy when used as a target of a local binding."); } ReportUpdateStatus(wasSet); return(true); } else { System.Diagnostics.Debug.WriteLine("Target IPropBag has been Garbage Collected on call to Update Target."); return(false); } }
private bool UpdateTargetWithStartingValue(WeakRefKey <IPropBag> bindingTarget, PropNode sourcePropNode) { IProp typedProp = sourcePropNode.PropData_Internal.TypedProp; PropStorageStrategyEnum ss = typedProp.PropTemplate.StorageStrategy; switch (ss) { case PropStorageStrategyEnum.Internal: { T newValue = (T)typedProp.TypedValueAsObject; bool result = UpdateTarget(bindingTarget, newValue); return(result); } case PropStorageStrategyEnum.External: goto case PropStorageStrategyEnum.Internal; // This property has no backing store, there is no concept of a starting value. case PropStorageStrategyEnum.Virtual: return(false); default: throw new InvalidOperationException($"{ss} is not a recognized or supported Prop Storage Strategy when used as a source for a local binding."); } }
private IConvertValues GetConverter(WeakRefKey <IPropBag> bindingTarget, LocalBindingInfo bInfo, Type sourceType, string pathElement, bool isPropBagBased, out object converterParameter) { //if (isPropBagBased) //{ // if (bInfo.Converter != null) // { // // Use the one specified in the MarkUp // converterParameter = bInfo.ConverterParameterBuilder(bindingTarget, bInfo, sourceType, pathElement); // return bInfo.Converter; // } // else // { // // Use the default for ItemsSource // if(bindingTarget.DependencyProperty.Name == "SelectedItem") // { // // If this is being used to supply a SelectedItem property. // converterParameter = null; // return new SelectedItemConverter(); // } // else // { // // Use the default converter provided by the caller or if no default provide our standard PropValueConverter. // converterParameter = DefaultConverterParameterBuilder(bindingTarget, bInfo, sourceType, pathElement); // return DefaultConverter.Value; // } // } //} //else //{ // // If no converter specified and the target is SelectedItem, // // use the SelectedItemConverter. // if (bInfo.Converter == null && bindingTarget.DependencyProperty?.Name == "SelectedItem") // { // converterParameter = null; // return new SelectedItemConverter(); // } // else // { // // TODO: Check this. I beleive that the Microsoft Binder supplies a default converter. // // If no converter specified in the markup, no converter will be used. // converterParameter = bInfo.ConverterParameterBuilder(bindingTarget, bInfo, sourceType, pathElement); // return bInfo.Converter; // } //} converterParameter = null; return(null); }
private void PropertyChangedWithTVals_Handler(object sender, PcTypedEventArgs <T> e) { // TODO: Include the original sender in the event data (and create a new event args class for this.) if (sender is WeakRefKey <IPropBag> propBag_wrKey) { LastEventSender = propBag_wrKey; } else { //LastEventSender = new WeakRefKey<IPropBag>(null); // Replaced above line with line below on 3/21/2018 (DRM) LastEventSender = new WeakRefKey <IPropBag>(sender as IPropBag); } OnPropertyChangedWithTVals(e); }
public override bool Equals(object o) { WeakRefKey weakRef = o as WeakRefKey; if (weakRef != null) { object target1 = Target; object target2 = weakRef.Target; if (target1 != null && target2 != null) { return(target1 == target2); } } return(base.Equals(o)); }
//Lazy<IValueConverter> _defaultConverter; //public virtual Lazy<IValueConverter> DefaultConverter //{ // get // { // if(_defaultConverter == null) // { // return new Lazy<IValueConverter>(() => new PropValueConverter()); // } // return _defaultConverter; // } // set // { // _defaultConverter = value; // } //} //Func<BindingTarget, MyBindingInfo, Type, string, object> _defConvParamBuilder; //public virtual Func<BindingTarget, MyBindingInfo, Type, string, object> DefaultConverterParameterBuilder //{ // get // { // if (_defConvParamBuilder == null) // { // return OurDefaultConverterParameterBuilder; // } // return _defConvParamBuilder; // } // set // { // _defConvParamBuilder = value; // } //} #endregion #region Constructor public LocalBinder(PSAccessServiceInterface propStoreAccessService, ExKeyT bindingTarget, LocalBindingInfo bindingInfo) { _bindingTarget = bindingTarget; _bindingInfo = bindingInfo; // Get the PropStore Node for the IPropBag object hosting the property that is the target of the binding. BagNode ourNode = GetPropBagNode(propStoreAccessService); // Get a weak reference to the PropBag hosting the target property. _targetObject = ourNode.PropBagProxy; // Get the name of the target property from the PropId given to us. if (_targetObject.TryGetTarget(out IPropBag propBag)) { PropIdType propId = _bindingTarget.Level2Key; _propertyName = GetPropertyName(propStoreAccessService, propBag, propId, out PropStorageStrategyEnum storageStrategy); if (storageStrategy == PropStorageStrategyEnum.External) { throw new InvalidOperationException($"{storageStrategy} is not a supported Prop Storage Strategy when used as a target of a local binding."); } // We will update the target property depending on how that PropItem stores its value. _targetStorageStrategy = storageStrategy; // Create a instance of our nested, internal class that reponds to Updates to the property store Nodes. IReceivePropStoreNodeUpdates_PropNode <T> propStoreNodeUpdateReceiver = new PropStoreNodeUpdateReceiver(this); // Create a new watcher, the bindingInfo specifies the PropItem for which to listen to changes, // the propStoreNodeUpdateReceiver will be notfied when changes occur. _localWatcher = new LocalWatcher <T>(propStoreAccessService, bindingInfo, propStoreNodeUpdateReceiver); } else { // TODO: consider creating a TryCreateLocalBinding to avoid this situation. System.Diagnostics.Debug.WriteLine("The target was found to have been Garbage Collected when creating a Local Binding."); } }
private ViewTable this[object o] { get { WeakRefKey weakRefKey = new WeakRefKey(o); WeakReference weakReference = null; ViewTable target = null; if (this.objectsToViewTables.TryGetValue(weakRefKey, out weakReference)) { target = (ViewTable)weakReference.Target; if (target == null) { this.objectsToViewTables.Remove(weakRefKey); } } return(target); } set { WeakRefKey weakRefKey = new WeakRefKey(o); this.objectsToViewTables[weakRefKey] = new WeakReference(value); } }
private ViewTable this[object o] { get { WeakRefKey weakRefKey = new WeakRefKey(o); WeakReference weakReference = null; ViewTable target = null; if (this.objectsToViewTables.TryGetValue(weakRefKey, out weakReference)) { target = (ViewTable)weakReference.Target; if (target == null) { this.objectsToViewTables.Remove(weakRefKey); } } return target; } set { WeakRefKey weakRefKey = new WeakRefKey(o); this.objectsToViewTables[weakRefKey] = new WeakReference(value); } }
private void DoUpdate(WeakRefKey <IPropBag> propItemParent_wr) { _localBinder._propItemParent_wr = propItemParent_wr; _localBinder.OnViewManagerChanged(); }
public void OnPropStoreNodeUpdated(WeakRefKey <IPropBag> propItemParent_wr) { DoUpdate(propItemParent_wr); }
// PropBag (Parent of PropItem) -- no old value. private bool NotifyReceiver(IReceivePropStoreNodeUpdates_PropBag <T> propStoreUpdateReceiver, WeakRefKey <IPropBag> propItemParent) { propStoreUpdateReceiver.OnPropStoreNodeUpdated(propItemParent); return(true); }
private object OurDefaultConverterParameterBuilder(WeakRefKey <IPropBag> bindingTarget, LocalBindingInfo bInfo, Type sourceType, string pathElement) { //return new TwoTypes(sourceType, bindingTarget.PropertyType); return(null); }