/// <summary> /// Subscribes to a dependency property changed handler /// </summary> /// <param name="dataContext">The DataContext that contains propertyName</param> /// <param name="propertyName">The property to observe</param> /// <param name="newValueAction">The action to execute when a new value is raised</param> /// <param name="disposeAction">The action to execute when the listener wants to dispose the subscription</param> /// <returns></returns> private static IDisposable SubscribeToDependencyPropertyChanged(ManagedWeakReference dataContextReference, string propertyName, Action newValueAction) { var dependencyObject = dataContextReference.Target as DependencyObject; if (dependencyObject != null) { var dp = Windows.UI.Xaml.DependencyProperty.GetProperty(dependencyObject.GetType(), propertyName); if (dp != null) { Windows.UI.Xaml.PropertyChangedCallback handler = (s, e) => newValueAction(); return(Windows.UI.Xaml.DependencyObjectExtensions .RegisterDisposablePropertyChangedCallback(dependencyObject, dp, handler)); } else { if (typeof(DependencyProperty).Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) { typeof(DependencyProperty).Log().DebugFormat( "Unable to find the dependency property [{0}] on type [{1}]" , propertyName , dependencyObject.GetType() ); } } } return(null); }
private void OnPropertyChanged(ManagedWeakReference instance, DependencyProperty property, DependencyPropertyChangedEventArgs args) { if (property == FillRuleProperty) { var rule = FillRule switch { FillRule.EvenOdd => "evenodd", FillRule.Nonzero => "nonzero", _ => "evenodd" }; _svgElement.SetAttribute("fill-rule", rule); } else if (property == ChildrenProperty) { _svgElement.ClearChildren(); if (args.OldValue is GeometryCollection oldGeometries) { oldGeometries.VectorChanged -= OnGeometriesChanged; } if (args.NewValue is GeometryCollection newGeometries) { newGeometries.VectorChanged += OnGeometriesChanged; newGeometries.SetParent(this); foreach (var child in Children) { _svgElement.AddChild(child.GetSvgElement()); } } } }
private void OnPropertyChanged(ManagedWeakReference instance, DependencyProperty property, DependencyPropertyChangedEventArgs args) { if (property == FiguresProperty) { if (args.OldValue is PathFigureCollection oldFigures) { oldFigures.VectorChanged -= OnFiguresVectorChanged; } if (args.NewValue is PathFigureCollection newFigures) { newFigures.VectorChanged += OnFiguresVectorChanged; } _svgElement.InvalidateMeasure(); } else if (property == FillRuleProperty) { var rule = FillRule switch { FillRule.EvenOdd => "evenodd", FillRule.Nonzero => "nonzero", _ => "evenodd" }; _svgElement.SetAttribute("fill-rule", rule); } }
private void OnPropertyChanged(ManagedWeakReference instance, DependencyProperty property, DependencyPropertyChangedEventArgs args) { if (property == RectProperty) { UpdateSvg(); } }
private void UpdateContentPresenter() { if (_contentPresenter != null) { var item = GetSelectionContent(); var itemView = item as _View; if (itemView != null) { #if __ANDROID__ var comboBoxItem = itemView.FindFirstParentOfView <ComboBoxItem>(); #else var comboBoxItem = itemView.FindFirstParent <ComboBoxItem>(); #endif if (comboBoxItem != null) { // Keep track of the former parent, so we can put the item back when the dropdown is shown _selectionParentInDropdown = (itemView.GetVisualTreeParent() as IWeakReferenceProvider)?.WeakReference; } } else { _selectionParentInDropdown = null; } _contentPresenter.Content = item; if (itemView != null && itemView.GetVisualTreeParent() != _contentPresenter) { // Item may have been put back in list, reattach it to _contentPresenter _contentPresenter.AddChild(itemView); } } }
public TextBoxView(TextBox owner) : base(ContextHelper.Current) { _ownerRef = WeakReferencePool.RentWeakReference(this, owner); InitializeBinder(); base.SetSingleLine(true); //This Background color is set to remove the native android underline on the EditText. this.SetBackgroundColor(Colors.Transparent); //Remove default native padding. this.SetPadding(0, 0, 0, 0); if (FeatureConfiguration.TextBox.HideCaret) { SetCursorVisible(false); } _isInitialized = true; // This ensures the TextBoxView gets resized as Text changes LayoutParameters = new Android.Views.ViewGroup.LayoutParams( Android.Views.ViewGroup.LayoutParams.WrapContent, Android.Views.ViewGroup.LayoutParams.WrapContent ); }
public AttachedDependencyObject(object owner) { InitializeBinder(); Owner = owner; OwnerWeakReference = WeakReferencePool.RentWeakReference(this, owner); }
public DependencyPropertyDetailsCollection(Type ownerType, ManagedWeakReference ownerReference, DependencyProperty dataContextProperty, DependencyProperty templatedParentProperty) { _ownerType = ownerType; _ownerReference = ownerReference; _dataContextProperty = dataContextProperty; _templatedParentProperty = templatedParentProperty; }
public XamlInfo(DependencyObject xamlOwner) { if (xamlOwner is IWeakReferenceProvider provider) { _owner = provider.WeakReference; } else { throw new NotSupportedException($"The provided reference must be an " + nameof(IWeakReferenceProvider)); } }
private void OnPropertyChanged(ManagedWeakReference instance, DependencyProperty property, DependencyPropertyChangedEventArgs args) { if (property == Controls.Canvas.TopProperty) { _canvasTop = (double)args.NewValue; } else if (property == Controls.Canvas.LeftProperty) { _canvasLeft = (double)args.NewValue; } }
/// <summary> /// Creates an instance using the specified DependencyObject <see cref="Type"/> /// </summary> /// <param name="ownerType">The owner type</param> public DependencyPropertyDetailsCollection(Type ownerType, ManagedWeakReference ownerReference, DependencyProperty dataContextProperty, DependencyProperty templatedParentProperty) { _ownerType = ownerType; _ownerReference = ownerReference; var propertiesForType = DependencyProperty.GetPropertiesForType(ownerType); var entries = _pool.Rent(propertiesForType.Length); for (int i = 0; i < propertiesForType.Length; i++) { ref var entry = ref entries[i]; entry.Id = propertiesForType[i].UniqueId; entry.Details = null; }
private void OnPropertyChanged(ManagedWeakReference instance, DependencyProperty property, DependencyPropertyChangedEventArgs args) { if (property == StartPointProperty) { var point = StartPoint; _svgElement.SetAttribute( ("x1", point.X.ToStringInvariant()), ("y1", point.Y.ToStringInvariant())); } else if (property == EndPointProperty) { var point = EndPoint; _svgElement.SetAttribute( ("x2", point.X.ToStringInvariant()), ("y2", point.Y.ToStringInvariant())); } }
/// <summary> /// Creates an instance using the specified DependencyObject <see cref="Type"/> /// </summary> /// <param name="ownerType">The owner type</param> public DependencyPropertyDetailsCollection(Type ownerType, ManagedWeakReference ownerReference, DependencyProperty dataContextProperty, DependencyProperty templatedParentProperty) { _ownerType = ownerType; _ownerReference = ownerReference; var propertiesForType = DependencyProperty.GetPropertiesForType(ownerType); var entries = new PropertyEntry[propertiesForType.Length]; for (int i = 0; i < propertiesForType.Length; i++) { entries[i].Id = propertiesForType[i].UniqueId; } // Entries are pre-sorted by the DependencyProperty.GetPropertiesForType method AssignEntries(entries, sort: false); // Prefecth known properties for faster access DataContextPropertyDetails = GetPropertyDetails(dataContextProperty); TemplatedParentPropertyDetails = GetPropertyDetails(templatedParentProperty); }
private void OnPropertyChanged(ManagedWeakReference instance, DependencyProperty property, DependencyPropertyChangedEventArgs args) { if (property == CenterProperty) { var center = Center; _svgElement.SetAttribute( ("cx", center.X.ToStringInvariant()), ("cy", center.Y.ToStringInvariant())); _svgElement.InvalidateMeasure(); } else if (property == RadiusXProperty) { _svgElement.SetAttribute("rx", RadiusX.ToStringInvariant()); _svgElement.InvalidateMeasure(); } else if (property == RadiusYProperty) { _svgElement.SetAttribute("ry", RadiusY.ToStringInvariant()); _svgElement.InvalidateMeasure(); } }
public DependencyPropertyDetailsCollection(Type ownerType, ManagedWeakReference ownerReference, DependencyProperty dataContextProperty, DependencyProperty templatedParentProperty) { _ownerType = ownerType; _ownerReference = ownerReference; var propertiesForType = DependencyProperty.GetPropertiesForType(ownerType); if (propertiesForType.Length != 0) { _minId = propertiesForType[0].UniqueId; _maxId = propertiesForType[propertiesForType.Length - 1].UniqueId; var entriesLength = _maxId - _minId + 1; var entries = _pool.Rent(entriesLength); // Entries are pre-sorted by the DependencyProperty.GetPropertiesForType method AssignEntries(entries, entriesLength); } _dataContextProperty = dataContextProperty; _templatedParentProperty = templatedParentProperty; }
public DropDownLayouter(ComboBox combo, PopupBase popup) { _combo = (combo as IWeakReferenceProvider).WeakReference; _popup = (popup as IWeakReferenceProvider).WeakReference; }
public XamlScope Push(ManagedWeakReference source) => new XamlScope(_resourceSources.Push(source));
/// <summary> /// Sets the specified <paramref name="binding"/> on the <paramref name="target"/> instance. /// </summary> internal void SetBinding(DependencyProperty dependencyProperty, Binding binding, ManagedWeakReference target) { if (GetPropertyDetails(dependencyProperty) is DependencyPropertyDetails details) { // Clear previous binding, to avoid erroneously pushing two-way value to it details.ClearBinding(); var bindingExpression = new BindingExpression( viewReference: target, targetPropertyDetails: details, binding: binding ); details.SetBinding(bindingExpression); if (Equals(binding.RelativeSource, RelativeSource.TemplatedParent)) { _templateBindings = _templateBindings.Add(bindingExpression); ApplyBinding(bindingExpression, TemplatedParentPropertyDetails.GetValue()); } else { _bindings = _bindings.Add(bindingExpression); if (bindingExpression.TargetPropertyDetails.Property.UniqueId == DataContextPropertyDetails.Property.UniqueId) { bindingExpression.DataContext = details.GetValue(DependencyPropertyValuePrecedences.Inheritance); } else { ApplyBinding(bindingExpression, DataContextPropertyDetails.GetValue()); } } } }
public TextBoxStringBuilder(ManagedWeakReference owner, ICharSequence text) : base(text) { _owner = owner; }
public Factory(ManagedWeakReference owner) { _owner = owner; }
private void UpdateContentPresenter() { if (_contentPresenter == null) { return; } if (SelectedItem != null) { var item = GetSelectionContent(); var itemView = item as _View; if (itemView != null) { #if __ANDROID__ var comboBoxItem = itemView.FindFirstParentOfView <ComboBoxItem>(); #else var comboBoxItem = itemView.FindFirstParent <ComboBoxItem>(); #endif if (comboBoxItem != null) { // Keep track of the former parent, so we can put the item back when the dropdown is shown _selectionParentInDropdown = (itemView.GetVisualTreeParent() as IWeakReferenceProvider)?.WeakReference; } } else { _selectionParentInDropdown = null; } _contentPresenter.Content = item; if (itemView != null && itemView.GetVisualTreeParent() != _contentPresenter) { // Item may have been put back in list, reattach it to _contentPresenter _contentPresenter.AddChild(itemView); } if (!_areItemTemplatesForwarded) { SetContentPresenterBinding(ContentPresenter.ContentTemplateProperty, nameof(ItemTemplate)); SetContentPresenterBinding(ContentPresenter.ContentTemplateSelectorProperty, nameof(ItemTemplateSelector)); _areItemTemplatesForwarded = true; } } else { _contentPresenter.Content = _placeholderTextBlock; if (_areItemTemplatesForwarded) { _contentPresenter.ClearValue(ContentPresenter.ContentTemplateProperty); _contentPresenter.ClearValue(ContentPresenter.ContentTemplateSelectorProperty); _areItemTemplatesForwarded = false; } } void SetContentPresenterBinding(DependencyProperty targetProperty, string sourcePropertyPath) { _contentPresenter.SetBinding(targetProperty, new Binding(sourcePropertyPath) { RelativeSource = RelativeSource.TemplatedParent }); } }
/// <summary> /// Push a new Resources source to the current xaml scope. /// </summary> internal static void PushSourceToScope(ManagedWeakReference source) { var current = _scopeStack.Pop(); _scopeStack.Push(current.Push(source)); }
public WeakResourceInitializer(object owner, ResourceInitializerWithOwner initializer) { _owner = WeakReferencePool.RentWeakReference(this, owner); Initializer = () => initializer(_owner?.Target); }