コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: GeometryGroup.wasm.cs プロジェクト: terwoord/uno
        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());
                    }
                }
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
 private void OnPropertyChanged(ManagedWeakReference instance, DependencyProperty property, DependencyPropertyChangedEventArgs args)
 {
     if (property == RectProperty)
     {
         UpdateSvg();
     }
 }
コード例 #5
0
ファイル: ComboBox.cs プロジェクト: RLittlesII/uno
        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);
                }
            }
        }
コード例 #6
0
        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
                );
        }
コード例 #7
0
        public AttachedDependencyObject(object owner)
        {
            InitializeBinder();

            Owner = owner;
            OwnerWeakReference = WeakReferencePool.RentWeakReference(this, owner);
        }
コード例 #8
0
        public DependencyPropertyDetailsCollection(Type ownerType, ManagedWeakReference ownerReference, DependencyProperty dataContextProperty, DependencyProperty templatedParentProperty)
        {
            _ownerType      = ownerType;
            _ownerReference = ownerReference;

            _dataContextProperty     = dataContextProperty;
            _templatedParentProperty = templatedParentProperty;
        }
コード例 #9
0
ファイル: XamlInfo.cs プロジェクト: zzyzy/uno
 public XamlInfo(DependencyObject xamlOwner)
 {
     if (xamlOwner is IWeakReferenceProvider provider)
     {
         _owner = provider.WeakReference;
     }
     else
     {
         throw new NotSupportedException($"The provided reference must be an " + nameof(IWeakReferenceProvider));
     }
 }
コード例 #10
0
ファイル: UIElement.skia.cs プロジェクト: unoplatform/uno
 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;
     }
 }
コード例 #11
0
        /// <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;
            }
コード例 #12
0
 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()));
     }
 }
コード例 #13
0
        /// <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);
        }
コード例 #14
0
        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();
            }
        }
コード例 #15
0
        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;
        }
コード例 #16
0
 public DropDownLayouter(ComboBox combo, PopupBase popup)
 {
     _combo = (combo as IWeakReferenceProvider).WeakReference;
     _popup = (popup as IWeakReferenceProvider).WeakReference;
 }
コード例 #17
0
ファイル: XamlScope.cs プロジェクト: jokm1/uno-2
 public XamlScope Push(ManagedWeakReference source) => new XamlScope(_resourceSources.Push(source));
コード例 #18
0
        /// <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());
                    }
                }
            }
        }
コード例 #19
0
 public TextBoxStringBuilder(ManagedWeakReference owner, ICharSequence text) : base(text)
 {
     _owner = owner;
 }
コード例 #20
0
 public Factory(ManagedWeakReference owner)
 {
     _owner = owner;
 }
コード例 #21
0
ファイル: ComboBox.cs プロジェクト: jokm1/uno-2
        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
                });
            }
        }
コード例 #22
0
ファイル: ResourceResolver.cs プロジェクト: zhuzilyy/uno
        /// <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));
        }
コード例 #23
0
 public WeakResourceInitializer(object owner, ResourceInitializerWithOwner initializer)
 {
     _owner      = WeakReferencePool.RentWeakReference(this, owner);
     Initializer = () => initializer(_owner?.Target);
 }