コード例 #1
0
ファイル: CachedImage.cs プロジェクト: llenroc/FFImageLoading
 static void OnSourcePropertyChanged(BindableObject bindable, object oldValue, object newValue)
 {
     if (newValue != null)
     {
         BindableObject.SetInheritedBindingContext(newValue as BindableObject, bindable.BindingContext);
     }
 }
コード例 #2
0
 internal void SetInheritedBindingContext(object bindingContext)
 {
     foreach (var item in Items)
     {
         BindableObject.SetInheritedBindingContext(item, bindingContext);
     }
 }
コード例 #3
0
        public (UIView NativeView, VisualElement FormsElement) RealizeEmptyView(object emptyView, DataTemplate emptyViewTemplate)
        {
            if (emptyViewTemplate != null)
            {
                // We have a template; turn it into a Forms view
                var templateElement = emptyViewTemplate.CreateContent() as View;
                var renderer        = CreateRenderer(templateElement);

                // and set the EmptyView as its BindingContext
                BindableObject.SetInheritedBindingContext(renderer.Element, emptyView);

                return(renderer.NativeView, renderer.Element);
            }

            if (emptyView is View formsView)
            {
                // No template, and the EmptyView is a Forms view; use that
                var renderer = CreateRenderer(formsView);

                return(renderer.NativeView, renderer.Element);
            }

            // No template, EmptyView is not a Forms View, so just display EmptyView.ToString
            var label = new UILabel {
                Text = emptyView.ToString()
            };

            return(label, null);
        }
コード例 #4
0
        /// From the Container base class.

        /// <summary>
        /// Adds a child view to this layer.
        /// </summary>
        /// <seealso cref="Container.Add">
        /// </seealso>
        /// <exception cref="ArgumentNullException"> Thrown when child is null. </exception>
        /// <since_tizen> 4 </since_tizen>
        public override void Add(View child)
        {
            if (null == child)
            {
                throw new ArgumentNullException(nameof(child));
            }

            Container oldParent = child.GetParent();

            if (oldParent != this)
            {
                if (oldParent != null)
                {
                    oldParent.Remove(child);
                }
                else
                {
                    child.InternalParent = this;
                }
                Interop.Actor.Add(SwigCPtr, View.getCPtr(child));
                if (NDalicPINVOKE.SWIGPendingException.Pending)
                {
                    throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                }
                Children.Add(child);
                BindableObject.SetInheritedBindingContext(child, this?.BindingContext);
            }
        }
コード例 #5
0
        public static (UIView NativeView, VisualElement FormsElement) RealizeView(object view, DataTemplate viewTemplate, ItemsView itemsView)
        {
            if (viewTemplate != null)
            {
                // Run this through the extension method in case it's really a DataTemplateSelector
                viewTemplate = viewTemplate.SelectDataTemplate(view, itemsView);

                // We have a template; turn it into a Forms view
                var templateElement = viewTemplate.CreateContent() as View;
                var renderer        = CreateRenderer(templateElement);

                // and set the EmptyView as its BindingContext
                BindableObject.SetInheritedBindingContext(renderer.Element, view);

                return(renderer.NativeView, renderer.Element);
            }

            if (view is View formsView)
            {
                // No template, and the EmptyView is a Forms view; use that
                var renderer = CreateRenderer(formsView);

                return(renderer.NativeView, renderer.Element);
            }

            return(new UILabel {
                Text = $"{view}"
            }, null);
        }
コード例 #6
0
 static void OnSourcePropertyChanged(BindableObject bindable, object oldValue, object newValue)
 {
     if (newValue != null)
     {
         BindableObject.SetInheritedBindingContext(newValue as BindableObject, bindable.BindingContext);
     }
     ((CachedImage)bindable).InvalidateMeasure();
 }
コード例 #7
0
 static void OnSourcePropertyChanged(BindableObject bindable, object oldValue, object newValue)
 {
     if (newValue != null)
     {
         BindableObject.SetInheritedBindingContext(newValue as BindableObject, bindable.BindingContext);
     }
     ((IVisualElementController)bindable).NativeSizeChanged();
 }
コード例 #8
0
 protected override void OnBindingContextChanged()
 {
     base.OnBindingContextChanged();
     foreach (BindableObject gradientStop in (Collection <DGradientStop>) this.GradientStops)
     {
         BindableObject.SetInheritedBindingContext(gradientStop, this.BindingContext);
     }
 }
コード例 #9
0
        void SetCell(object newContext)
        {
            var cell = newContext as Cell;

            if (cell != null)
            {
                Cell = cell;
                return;
            }

            if (ReferenceEquals(Cell?.BindingContext, newContext))
            {
                return;
            }

            // If there is a ListView, load the Cell content from the ItemTemplate.
            // Otherwise, the given Cell is already a templated Cell from a TableView.
            ListView lv = _listView.Value;

            if (lv != null)
            {
                bool         isGroupHeader  = IsGroupHeader;
                DataTemplate template       = isGroupHeader ? lv.GroupHeaderTemplate : lv.ItemTemplate;
                object       bindingContext = newContext;

                if (template is DataTemplateSelector)
                {
                    template = ((DataTemplateSelector)template).SelectTemplate(bindingContext, lv);
                }

                if (template != null)
                {
                    cell = template.CreateContent() as Cell;
                }
                else
                {
                    if (isGroupHeader)
                    {
                        bindingContext = lv.GetDisplayTextFromGroup(bindingContext);
                    }

                    cell = lv.CreateDefaultCell(bindingContext);
                }

                // A TableView cell should already have its parent,
                // but we need to set the parent for a ListView cell.
                cell.Parent = lv;

                // Set inherited BindingContext after setting the Parent so it won't be wiped out
                BindableObject.SetInheritedBindingContext(cell, bindingContext);

                // This provides the Group Header styling (e.g., larger font, etc.) when the
                // template is loaded later.
                cell.SetIsGroupHeader <ItemsView <Cell>, Cell>(isGroupHeader);
            }

            Cell = cell;
        }
コード例 #10
0
 private void SetupItems(IList items, BindableObject parent)
 {
     foreach (BindableObject item in items)
     {
         BindableObject.SetInheritedBindingContext(item, parent?.BindingContext);
         var element = (IWithParentElement)item;
         element.Parent = parent;
     }
 }
コード例 #11
0
 protected override void OnBindingContextChanged()
 {
     base.OnBindingContextChanged();
     if (this.BackgroundBrush == null)
     {
         return;
     }
     BindableObject.SetInheritedBindingContext((BindableObject)this.BackgroundBrush, this.BindingContext);
 }
コード例 #12
0
        private static void OnAudioPlayerBarChanged(BindableObject bindable, object oldValue, object newValue)
        {
            var newElement = (Element)newValue;

            if (newElement != null)
            {
                BindableObject.SetInheritedBindingContext(newElement, bindable.BindingContext);
            }
        }
コード例 #13
0
 private void SetupItems(IList items, SKCanvasView parent)
 {
     foreach (var item in items)
     {
         var element = (TElement)item;
         BindableObject.SetInheritedBindingContext(element, parent?.BindingContext);
         element.Parent = parent;
     }
 }
コード例 #14
0
        //
        // Methods
        //
        protected override void OnBindingContextChanged()
        {
            if (this.Source != null)
            {
                BindableObject.SetInheritedBindingContext(Source, BindingContext);
            }

            base.OnBindingContextChanged();
        }
コード例 #15
0
        internal void Release()
        {
            Parent = null;

            foreach (var item in Items)
            {
                BindableObject.SetInheritedBindingContext(item, null);
                item.Parent = null;
            }
        }
コード例 #16
0
        private static void OnBindingContextChanged(object sender, System.EventArgs e)
        {
            var skCanvasView   = (SKCanvasView)sender;
            var rendererSource = GetRenderer(skCanvasView);

            if (rendererSource is BindableObject bindable)
            {
                BindableObject.SetInheritedBindingContext(bindable, skCanvasView.BindingContext);
            }
        }
コード例 #17
0
        void ApplyTemplateAndDataContext(TemplatedCell cell, NSIndexPath indexPath)
        {
            // We need to create a renderer, which means we need a template
            var view = _itemsView.ItemTemplate.CreateContent() as View;

            _itemsView.AddLogicalChild(view);
            var renderer = CreateRenderer(view);

            BindableObject.SetInheritedBindingContext(view, _itemsSource[indexPath.Row]);
            cell.SetRenderer(renderer);
        }
コード例 #18
0
        public static void SetBindingContext(this IGradientControl control, object bindingContext)
        {
            if (control.GradientSource is BindableObject bindable)
            {
                BindableObject.SetInheritedBindingContext(bindable, bindingContext);
            }

            if (control.Mask is BindableObject maskBindable)
            {
                BindableObject.SetInheritedBindingContext(maskBindable, bindingContext);
            }
        }
コード例 #19
0
        void ApplyTemplateAndDataContext(TemplatedCell cell, NSIndexPath indexPath)
        {
            // We need to create a renderer, which means we need a template
            var templateElement             = _itemsView.ItemTemplate.CreateContent() as View;
            IVisualElementRenderer renderer = CreateRenderer(templateElement);

            if (renderer != null)
            {
                BindableObject.SetInheritedBindingContext(renderer.Element, _itemsSource[indexPath.Row]);
                cell.SetRenderer(renderer);
            }
        }
コード例 #20
0
        internal void AttachTo(SKCanvasView parent)
        {
            Parent = parent;

            foreach (var item in Items)
            {
                BindableObject.SetInheritedBindingContext(item, Parent?.BindingContext);
                item.Parent = parent;
            }

            Parent?.InvalidateSurface();
        }
コード例 #21
0
        internal void AttachTo(BindableObject parent)
        {
            Parent = parent;

            foreach (var item in Items)
            {
                BindableObject.SetInheritedBindingContext(item, Parent?.BindingContext);
                item.Parent = parent;
            }

            InvalidateParentCanvas();
        }
コード例 #22
0
        public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
        {
            switch (holder)
            {
            case TextViewHolder textViewHolder:
                textViewHolder.TextView.Text = _itemsSource[position].ToString();
                break;

            case TemplatedItemViewHolder templateViewHolder:
                BindableObject.SetInheritedBindingContext(templateViewHolder.View, _itemsSource[position]);
                break;
            }
        }
コード例 #23
0
        public override void InsertListRange(int index, IEnumerable <TemplatedItem <UIMeshItem> > enumerable)
        {
            var mesh     = (UIMesh)container;
            var oldCount = _builder.Count;

            _builder.InsertRange(index, enumerable);

            foreach (var item in _builder.Skip(oldCount))
            {
                BindableObject.SetInheritedBindingContext(item.Content, mesh.BindingContext);
                item.Content.mesh = mesh;
            }

            mesh.Body?.SetVerticesDirty();
        }
コード例 #24
0
        public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
        {
            if (EmptyView == null || EmptyViewTemplate == null)
            {
                return;
            }

            if (!(holder is EmptyViewHolder emptyViewHolder))
            {
                return;
            }

            // Use EmptyView as the binding context for the template
            BindableObject.SetInheritedBindingContext(emptyViewHolder.View, EmptyView);
        }
コード例 #25
0
        protected override void OnElementChanged(ElementChangedEventArgs <MediaElement> e)
        {
            if (e.OldElement != null)
            {
                e.OldElement.SeekRequested     -= OnSeekRequested;
                e.OldElement.StateRequested    -= OnStateRequested;
                e.OldElement.PositionRequested -= OnPositionRequested;
            }

            if (Control == null)
            {
                SetNativeControl(new LayoutCanvas(XForms.NativeParent));
                _mediaView             = new MediaView(XForms.NativeParent);
                Control.LayoutUpdated += (s, evt) => OnLayout();
                Control.Children.Add(_mediaView);
                Control.AllowFocus(true);

                _player = new MediaPlayer()
                {
                    VideoOutput = this
                };
                _player.PlaybackStarted          += OnPlaybackStarted;
                _player.PlaybackPaused           += OnPlaybackPaused;
                _player.PlaybackStopped          += OnPlaybackStopped;
                _player.PlaybackCompleted        += OnPlaybackCompleted;
                _player.BufferingProgressUpdated += OnBufferingProgressUpdated;
                _player.ErrorOccurred            += OnErrorOccurred;
                _player.MediaPrepared            += OnMediaPrepared;
                _player.BindingContext            = Element;
                _player.SetBinding(MediaPlayer.SourceProperty, "Source");
                _player.SetBinding(MediaPlayer.UsesEmbeddingControlsProperty, "ShowsPlaybackControls");
                _player.SetBinding(MediaPlayer.AutoPlayProperty, "AutoPlay");
                _player.SetBinding(MediaPlayer.VolumeProperty, "Volume");
                _player.SetBinding(MediaPlayer.IsLoopingProperty, "IsLooping");
                _player.SetBinding(MediaPlayer.AspectModeProperty, new Binding
                {
                    Path      = "Aspect",
                    Converter = new AspectToDisplayAspectModeConverter()
                });
                BindableObject.SetInheritedBindingContext(_player, Element.BindingContext);

                Element.SeekRequested     += OnSeekRequested;
                Element.StateRequested    += OnStateRequested;
                Element.PositionRequested += OnPositionRequested;
            }
            base.OnElementChanged(e);
        }
コード例 #26
0
        // From Container Base class
        /// <summary>
        /// Adds a child view to this view.
        /// </summary>
        /// <seealso cref="Container.Add" />
        /// <since_tizen> 4 </since_tizen>
        public override void Add(View child)
        {
            bool hasLayout = (_layout != null);

            if (null == child)
            {
                Tizen.Log.Fatal("NUI", "Child is null");
                return;
            }

            Container oldParent = child.GetParent();

            if (oldParent != this)
            {
                // If child already has a parent then re-parent child
                if (oldParent != null)
                {
                    if (child.Layout != null)
                    {
                        child.Layout.SetReplaceFlag();
                    }
                    oldParent.Remove(child);
                }
                child.InternalParent = this;

                Interop.Actor.Actor_Add(swigCPtr, View.getCPtr(child));

                if (NDalicPINVOKE.SWIGPendingException.Pending)
                {
                    throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                }
                Children.Add(child);

                if (ChildAdded != null)
                {
                    ChildAddedEventArgs e = new ChildAddedEventArgs
                    {
                        Added = child
                    };
                    ChildAdded(this, e);
                }
                BindableObject.SetInheritedBindingContext(child, this?.BindingContext);
            }
        }
コード例 #27
0
        public override void ReplaceListRange(int index, int count, IEnumerable <TemplatedItem <UIMeshItem> > enumerable)
        {
            var mesh = (UIMesh)container;

            foreach (var item in _builder.Skip(index).Take(count))
            {
                item.Content.Dispose();
            }

            base.ReplaceListRange(index, count, enumerable);

            foreach (var item in _builder.Skip(index).Take(count))
            {
                BindableObject.SetInheritedBindingContext(item.Content, mesh.BindingContext);
                item.Content.mesh = mesh;
            }

            mesh.Body?.SetVerticesDirty();
        }
コード例 #28
0
        void ApplyTemplateAndDataContext(TemplatedCell cell, NSString elementKind, NSIndexPath indexPath)
        {
            DataTemplate template;

            if (elementKind == UICollectionElementKindSectionKey.Header)
            {
                template = GroupableItemsView.GroupHeaderTemplate;
            }
            else
            {
                template = GroupableItemsView.GroupFooterTemplate;
            }

            var templateElement = template.CreateContent() as View;
            var renderer        = CreateRenderer(templateElement);

            BindableObject.SetInheritedBindingContext(renderer.Element, ItemsSource.Group(indexPath));
            cell.SetRenderer(renderer);
        }
コード例 #29
0
        private void UpdateInheritedBindingContexts()
        {
            object bindingContext           = base.BindingContext;
            RowDefinitionCollection rowDefs = this.RowDefinitions;

            if (rowDefs != null)
            {
                for (int i = 0; i < rowDefs.Count; i++)
                {
                    BindableObject.SetInheritedBindingContext(rowDefs[i], bindingContext);
                }
            }
            ColumnDefinitionCollection colDefs = this.ColumnDefinitions;

            if (colDefs != null)
            {
                for (int j = 0; j < colDefs.Count; j++)
                {
                    BindableObject.SetInheritedBindingContext(colDefs[j], bindingContext);
                }
            }
        }
コード例 #30
0
 protected override void OnBindingContextChanged()
 {
     BindableObject.SetInheritedBindingContext(Page, base.BindingContext);
     base.OnBindingContextChanged();
 }