internal ScrollToRequestedEventArgs(Element element, ScrollToPosition position, bool shouldAnimate)
		{
			Element = element;
			Position = position;
			ShouldAnimate = shouldAnimate;
			Mode = ScrollToMode.Element;
		}
Ejemplo n.º 2
0
 public static ParentObserver GetOrAdd(Element element)
 {
     return ServiceProvider
         .AttachedValueProvider
         .GetOrAdd(element, "#ParentListener", (frameworkElement, o) => new ParentObserver(frameworkElement),
             null);
 }
Ejemplo n.º 3
0
		protected override void OnChildAdded(Element child)
		{
			base.OnChildAdded(child);

			Page view = (Page)child;

			Page m = null;
			if (_mainPage == null || _mainPage.TryGetTarget (out m)) {
				// is null
				_mainPage = new WeakReference<Page> (view);
			} 

			_mainPage.TryGetTarget (out m);
			// Since OnChildRemoved event is not triggered for main page.
			if (CurrentPage == m) {
				OnNavigatingFrom (m, view);
			}
			// added 3-4-2015
			else if (CurrentPage != m && CurrentPage != null)
			{
				PagePushed(CurrentPage);
			}

			OnNavigatingTo(view, CurrentPage);
		}
Ejemplo n.º 4
0
		public ElementEventArgs(Element element)
		{
			if (element == null)
				throw new ArgumentNullException("element");

			Element = element;
		}
Ejemplo n.º 5
0
		void IPinchGestureController.SendPinch(Element sender, double delta, Point currentScalePoint)
		{
			EventHandler<PinchGestureUpdatedEventArgs> handler = PinchUpdated;
			if (handler != null)
			{
				handler(sender, new PinchGestureUpdatedEventArgs(GestureStatus.Running, delta, currentScalePoint));
			}
			((IPinchGestureController)this).IsPinching = true;
		}
Ejemplo n.º 6
0
		void IPinchGestureController.SendPinchStarted(Element sender, Point initialScalePoint)
		{
			EventHandler<PinchGestureUpdatedEventArgs> handler = PinchUpdated;
			if (handler != null)
			{
				handler(sender, new PinchGestureUpdatedEventArgs(GestureStatus.Started, 1, initialScalePoint));
			}
			((IPinchGestureController)this).IsPinching = true;
		}
Ejemplo n.º 7
0
		void IPinchGestureController.SendPinchEnded(Element sender)
		{
			EventHandler<PinchGestureUpdatedEventArgs> handler = PinchUpdated;
			if (handler != null)
			{
				handler(sender, new PinchGestureUpdatedEventArgs(GestureStatus.Completed));
			}
			((IPinchGestureController)this).IsPinching = false;
		}
Ejemplo n.º 8
0
		protected override void OnChildAdded (Element child)
		{
			base.OnChildAdded (child);

			//each time a child Image is added, add it to the ImageList
			if (child is Image) {
				//set a CurrentImage if we don't already have one
				if (CurrentImage == null) {
					CurrentImage = (Image)child;
				}
			}
		}
Ejemplo n.º 9
0
        public virtual void RemoveChild(XF.Element child)
        {
            if (child is null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            var sectionToRemove = GetSectionForElement(child)
                                  ?? throw new NotSupportedException($"Handler of type '{GetType().FullName}' representing element type '{TargetElement?.GetType().FullName ?? "<null>"}' doesn't support removing a child (child type is '{child.GetType().FullName}').");

            ShellItemControl.Items.Remove(sectionToRemove);
        }
Ejemplo n.º 10
0
        public static IEnumerable <Xamarin.Forms.Element> GetChildrenRecursive(this Xamarin.Forms.Element element)
        {
            foreach (var child in element.GetChildren())
            {
                yield return(child);

                foreach (var gchild in GetChildrenRecursive(child))
                {
                    yield return(gchild);
                }
            }
        }
Ejemplo n.º 11
0
        protected override void OnAddChild(VisualNode widget, Xamarin.Forms.Element childControl)
        {
            if (childControl is View view)
            {
                NativeControl.Content = view;
            }
            else
            {
                throw new InvalidOperationException($"Type '{childControl.GetType()}' not supported under '{GetType()}'");
            }

            base.OnAddChild(widget, childControl);
        }
        /// <summary>
        /// Gets a value indicating whether the <see cref="PlotViewBase"/> is connected to the visual tree.
        /// </summary>
        /// <returns><c>true</c> if the PlotViewBase is connected to the visual tree; <c>false</c> otherwise.</returns>
        private bool IsInVisualTree()
        {
            Xamarin.Forms.Element dpObject = this;
            while ((dpObject = dpObject.Parent) != null)
            {
                if (dpObject is Page)
                {
                    return(true);
                }
            }

            return(false);
        }
        private Page GetContainingPage(Xamarin.Forms.Element element)
        {
            Element parentElement = element.ParentView;

            if (typeof(Page).IsAssignableFrom(parentElement.GetType()))
            {
                return((Page)parentElement);
            }
            else
            {
                return(GetContainingPage(parentElement));
            }
        }
Ejemplo n.º 14
0
        public int GetChildIndex(XF.Element child)
        {
            // There are two cases to consider:
            // 1. A Xamarin.Forms Label can have only 1 child (a FormattedString), so the child's index is always 0.
            // 2. But to simplify things, in MobileBlazorBindings a Label can contain a Span directly, so if the child
            //    is a Span, we have to compute its sibling index.

            return(child switch
            {
                XF.Span span => LabelControl.FormattedText?.Spans.IndexOf(span) ?? -1,
                XF.FormattedString formattedString when LabelControl.FormattedText == formattedString => 0,
                _ => - 1
            });
Ejemplo n.º 15
0
		/// <summary>
		/// Invoked whenever the <see cref="E:Xamarin.Forms.Element.ChildRemoved" /> event needs to be emitted. Implement this method to add class handling for this event.
		/// </summary>
		/// <param name="child">The element that was removed.</param>
		/// <remarks>This method has no default implementation. You should still call the base implementation in case an intermediate class has implemented this method.</remarks>
		protected override void OnChildRemoved(Element child)
		{
			base.OnChildRemoved(child);

			Page view = (Page)child;

			OnNavigatingFrom(view, _previousPage);

			// Since OnChildAdded is not triggered for main page.
			if (_previousPage == _mainPage)
			{
				OnNavigatingTo(_mainPage, view);
			}
		}
Ejemplo n.º 16
0
        /// <summary>
        /// Gets the relative layout that is to be used as the container.
        /// </summary>
        /// <param name="element">The element to get the parent layout for.</param>
        /// <returns>The relative layout that is the parent of the given element.</returns>
        internal static RelativeLayout GetContainer(Element element)
        {
            if (element == null)
            {
                throw new InvalidOperationException("Can not find the parent layout for the given element.");
            }

            if (element.Parent is RelativeLayout)
            {
                return (RelativeLayout)element.Parent;
            }

            return GetContainer(element.Parent);
        }
Ejemplo n.º 17
0
        public void SetParent(XF.Element parent)
        {
            if (parent is null)
            {
                throw new ArgumentNullException(nameof(parent));
            }
            if (!(parent is XF.VisualElement parentVisualElement))
            {
                throw new ArgumentNullException(nameof(parent), $"Expected parent to be of type '{typeof(XF.VisualElement).FullName}' but it is of type '{parent.GetType().FullName}'.");
            }
            _parentVisualElement = parentVisualElement;

            UpdateParentStyleSheetIfPossible();
        }
        protected override void OnAddChild(VisualNode widget, Xamarin.Forms.Element childControl)
        {
            if (childControl is View view)
            {
                //System.Diagnostics.Debug.WriteLine($"StackLayout ({Key ?? GetType()}) inserting {widget.Key ?? widget.GetType()} at index {widget.ChildIndex}");
                NativeControl.Children.Insert(widget.ChildIndex, view);
            }
            else
            {
                throw new InvalidOperationException($"Type '{childControl.GetType()}' not supported under '{GetType()}'");
            }

            base.OnAddChild(widget, childControl);
        }
Ejemplo n.º 19
0
        public static T FindParent <T>(this Xamarin.Forms.Element element)
        {
            Element parent = element;

            while (parent != null)
            {
                parent = parent.Parent;
                if (parent is T found)
                {
                    return(found);
                }
            }
            return(default(T));
        }
        public virtual void AddChild(XF.Element child, int physicalSiblingIndex)
        {
            var childAsPage = child as XF.Page;

            if (physicalSiblingIndex <= TabbedPageControl.Children.Count)
            {
                TabbedPageControl.Children.Insert(physicalSiblingIndex, childAsPage);
            }
            else
            {
                Debug.WriteLine($"WARNING: {nameof(AddChild)} called with {nameof(physicalSiblingIndex)}={physicalSiblingIndex}, but TabbedPageControl.Children.Count={TabbedPageControl.Children.Count}");
                TabbedPageControl.Children.Add(childAsPage);
            }
        }
Ejemplo n.º 21
0
		protected override void OnChildRemoved(Element child)
		{
			base.OnChildRemoved(child);

			Page view = (Page)child;

			Page currentView = null;
			Page previousView = null;
			_previousPage.TryGetTarget (out currentView);
			_mainPage.TryGetTarget (out previousView);

			/* OLD BLOCK removed 3-5-2015 */
//			OnNavigatingFrom(view, currentView);
//
//			// Since OnChildAdded is not triggered for main page.
//			if (currentView == previousView) {
//
//				// added 2-11-2015
////				var test = view as IPage;
////				if (test != null)
////					test.FirePageRemoved ();
////
//				OnNavigatingTo (currentView, view);
//			}
//			// added 3-5-2015 (to remove event handlers)
//			else if (previousView != null && currentView != null && (currentView != previousView)) {
//				PagePushed (previousView);
//			}

			/* END OLD BLOCK */
			// switched to this from above comments

			// Since OnChildAdded is not triggered for main page.
			if (currentView == previousView) {

				// added 2-11-2015
				//				var test = view as IPage;
				//				if (test != null)
				//					test.FirePageRemoved ();
				//
				OnNavigatingTo (currentView, view);
			}
			// added 3-5-2015 (to remove event handlers)
			else if (previousView != null && currentView != null && (currentView != previousView)) {
				PagePushed (previousView);
			}

			OnNavigatingFrom(view, currentView);
		}
Ejemplo n.º 22
0
        public void AddChild(XF.Element child, int physicalSiblingIndex)
        {
            if (!(child is XF.View childView))
            {
                throw new ArgumentException($"Expected parent to be of type {typeof(XF.View).FullName} but it is of type {child?.GetType().FullName}.", nameof(child));
            }

            XF.Grid.SetColumn(childView, Column);
            XF.Grid.SetColumnSpan(childView, ColumnSpan);
            XF.Grid.SetRow(childView, Row);
            XF.Grid.SetRowSpan(childView, RowSpan);

            _children.Add(childView);
            _parentGrid.Children.Add(childView);
        }
Ejemplo n.º 23
0
        public bool Update()
        {
                        #if TRIAL
            var       mem        = Plugin.Settings.CrossSettings.Current;
            const int TrialLimit = 30;
            int       TrialLeft  = mem.GetValueOrDefault <int> ("Cross.Pie.Forms.Pro.Trial.CountDown", TrialLimit);
            if (TrialLeft <= 0)
            {
                Xamarin.Forms.Element element = this;
                Page ifPage = null;
                do
                {
                    element = element.Parent;
                    ifPage  = element as ContentPage;
                    if (ifPage != null)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            // Analysis disable once ConvertToLambdaExpression
                            ifPage.DisplayAlert("Limit", string.Format("Trial version limit to {0} times.", TrialLimit), "OK");
                        });
                        break;
                    }
                }while(element != null);
                return(false);
            }
            TrialLeft--;
            mem.AddOrUpdateValue <int>("Cross.Pie.Forms.Pro.Trial.CountDown", TrialLeft);
                        #endif

            if (ListItems == null)
            {
                return(false);
            }
            if (ListItems.Count <= 0)
            {
                return(false);
            }
            var sumValue = ListItems.Aggregate <PieItem, double>(0.0, (sum, eachObject) => sum + eachObject.Value);

            foreach (var each in ListItems)
            {
                each.Prepare(sumValue);
            }
            Invalidate();

            return(true);
        }
Ejemplo n.º 24
0
        public static IEnumerable <Xamarin.Forms.Element> GetChildren(this Xamarin.Forms.Element element)
        {
            if (element == null)
            {
                yield break;
            }

            var typ = element.GetType();

            if (typeof(Cell).IsAssignableFrom(typ))
            {
                var cell = element as Cell;
                if (typeof(ViewCell).IsAssignableFrom(typ))
                {
                    yield return((element as ViewCell).View);
                }
            }
            else if (typeof(ContentPage).IsAssignableFrom(typ))
            {
                var page = element as ContentPage;
                yield return(page.Content);
            }
            else if (typeof(Layout <View>).IsAssignableFrom(typ))
            {
                var layout = element as Layout <View>;
                foreach (var child in layout.Children)
                {
                    yield return(child);
                }
            }
            else if (typeof(Layout).IsAssignableFrom(typ))
            {
                var layout = element as Layout;
                foreach (var child in layout.Children)
                {
                    yield return(child);
                }
            }
            else if (typeof(ITemplatedItemsView <Cell>).IsAssignableFrom(typ))
            {
                var tiv = element as ITemplatedItemsView <Cell>;
                foreach (var cell in tiv.TemplatedItems)
                {
                    yield return(cell);
                }
            }
            yield break;
        }
Ejemplo n.º 25
0
        public override void AddChild(XF.Element child, int physicalSiblingIndex)
        {
            var childAsView = child as XF.View;

            var layoutControlOfView = LayoutControl as XF.Layout <XF.View>;

            if (physicalSiblingIndex <= layoutControlOfView.Children.Count)
            {
                layoutControlOfView.Children.Insert(physicalSiblingIndex, childAsView);
            }
            else
            {
                Debug.WriteLine($"WARNING: {nameof(AddChild)} called with {nameof(physicalSiblingIndex)}={physicalSiblingIndex}, but layoutControlOfView.Children.Count={layoutControlOfView.Children.Count}");
                layoutControlOfView.Children.Add(childAsView);
            }
        }
 private static ElementHandler CreateHandler(XF.Element parent, MobileBlazorBindingsRenderer renderer)
 {
     return(parent switch
     {
         XF.ContentPage contentPage => new ContentPageHandler(renderer, contentPage),
         XF.ContentView contentView => new ContentViewHandler(renderer, contentView),
         XF.Label label => new LabelHandler(renderer, label),
         XF.FlyoutPage flyoutPage => new FlyoutPageHandler(renderer, flyoutPage),
         XF.ScrollView scrollView => new ScrollViewHandler(renderer, scrollView),
         XF.ShellContent shellContent => new ShellContentHandler(renderer, shellContent),
         XF.Shell shell => new ShellHandler(renderer, shell),
         XF.ShellItem shellItem => new ShellItemHandler(renderer, shellItem),
         XF.ShellSection shellSection => new ShellSectionHandler(renderer, shellSection),
         XF.TabbedPage tabbedPage => new TabbedPageHandler(renderer, tabbedPage),
         _ => new ElementHandler(renderer, parent),
     });
Ejemplo n.º 27
0
        public virtual void RemoveChild(XF.Element child)
        {
            if (child is null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            XF.ShellContent contentToRemove = child switch
            {
                XF.TemplatedPage childAsTemplatedPage => GetContentForTemplatePage(childAsTemplatedPage),
                XF.ShellContent childAsShellContent => childAsShellContent,
                _ => throw new NotSupportedException($"Handler of type '{GetType().FullName}' representing element type '{TargetElement?.GetType().FullName ?? "<null>"}' doesn't support removing a child (child type is '{child.GetType().FullName}').")
            };

            ShellSectionControl.Items.Remove(contentToRemove);
        }
Ejemplo n.º 28
0
        public virtual void AddChild(XF.Element child, int physicalSiblingIndex)
        {
            var childAsSpan = child as XF.Span;

            var formattedString = GetFormattedString();

            if (physicalSiblingIndex <= formattedString.Spans.Count)
            {
                formattedString.Spans.Insert(physicalSiblingIndex, childAsSpan);
            }
            else
            {
                Debug.WriteLine($"WARNING: {nameof(AddChild)} called with {nameof(physicalSiblingIndex)}={physicalSiblingIndex}, but Label.FormattedText.Spans.Count={LabelControl.FormattedText.Spans.Count}");
                formattedString.Spans.Add(childAsSpan);
            }
        }
        public void AddChild(XF.Element child, int physicalSiblingIndex)
        {
            if (!(child is XF.GradientStop gradientStopChild))
            {
                throw new ArgumentException($"GradientBrush support GradientStop child elements only, but {child?.GetType()} found instead.", nameof(child));
            }

            if (physicalSiblingIndex <= GradientBrushControl.GradientStops.Count)
            {
                GradientBrushControl.GradientStops.Insert(physicalSiblingIndex, gradientStopChild);
            }
            else
            {
                Debug.WriteLine($"WARNING: {nameof(AddChild)} called with {nameof(physicalSiblingIndex)}={physicalSiblingIndex}, but GradientBrushControl.GradientStops.Count={GradientBrushControl.GradientStops}");
                GradientBrushControl.GradientStops.Add(gradientStopChild);
            }
        }
        private ViewCell GetContainingViewCell(Xamarin.Forms.Element element)
        {
            Element parentElement = element.Parent;

            if (parentElement == null)
            {
                return(null);
            }

            if (typeof(ViewCell).IsAssignableFrom(parentElement.GetType()))
            {
                return((ViewCell)parentElement);
            }
            else
            {
                return(GetContainingViewCell(parentElement));
            }
        }
Ejemplo n.º 31
0
        protected override void OnAddChild(VisualNode widget, Xamarin.Forms.Element childControl)
        {
            if (childControl is View view)
            {
                Grid.SetRow(childControl, widget.GetMetadata <int>("Grid.Row"));
                Grid.SetRowSpan(childControl, widget.GetMetadata <int>("Grid.RowSpan", 1));
                Grid.SetColumn(childControl, widget.GetMetadata <int>("Grid.Column"));
                Grid.SetColumnSpan(childControl, widget.GetMetadata <int>("Grid.ColumnSpan", 1));

                NativeControl.Children.Insert(widget.ChildIndex, view);
            }
            else
            {
                throw new InvalidOperationException($"Type '{childControl.GetType()}' not supported under '{GetType()}'");
            }

            base.OnAddChild(widget, childControl);
        }
Ejemplo n.º 32
0
        public static Xamarin.Forms.ListView GetContainingListView(Xamarin.Forms.Element element)
        {
            Element parentElement = element.ParentView;

            if (parentElement == null)
            {
                return(null);
            }

            if (GetType <Xamarin.Forms.ListView>().IsAssignableFrom(GetType(parentElement)))
            {
                return((Xamarin.Forms.ListView)parentElement);
            }
            else
            {
                return(GetContainingListView(parentElement));
            }
        }
Ejemplo n.º 33
0
        public static Page GetContainingPage(Xamarin.Forms.Element element)
        {
            Element parentElement = element.ParentView;

            if (parentElement == null)
            {
                return(null);
            }

            if (GetType <Page>().IsAssignableFrom(GetType(parentElement)))
            {
                return((Page)parentElement);
            }
            else
            {
                return(GetContainingPage(parentElement));
            }
        }
Ejemplo n.º 34
0
        public static ViewCell GetContainingViewCell(Xamarin.Forms.Element element)
        {
            Element parentElement = element.Parent;

            if (parentElement == null)
            {
                return(null);
            }

            if (GetType <ViewCell>().IsAssignableFrom(GetType(parentElement)))
            {
                return((ViewCell)parentElement);
            }
            else
            {
                return(GetContainingViewCell(parentElement));
            }
        }
Ejemplo n.º 35
0
		/// <summary>
		/// Invoked whenever the <see cref="E:Xamarin.Forms.Element.ChildAdded" /> event needs to be emitted. Implement this method to add class handling for this event.
		/// </summary>
		/// <param name="child">The element that was added.</param>
		/// <remarks>This method has no default implementation. You should still call the base implementation in case an intermediate class has implemented this method.</remarks>
		protected override void OnChildAdded(Element child)
		{
			base.OnChildAdded(child);

			Page view = (Page)child;

			if (_mainPage == null)
			{
				_mainPage = view;
			}

			// Since OnChildRemoved event is not triggered for main page.
			if (CurrentPage == _mainPage)
			{
				OnNavigatingFrom(_mainPage, view);
			}

			OnNavigatingTo(view, CurrentPage);
		}
Ejemplo n.º 36
0
        public static IEnumerable <T> CollectElements <T>(this Xamarin.Forms.Element element) where T : Xamarin.Forms.Element
        {
            if (element == null)
            {
                yield break;
            }

            foreach (var child in element.GetChildrenRecursive())
            {
                if (typeof(T).IsAssignableFrom(child.GetType()))
                {
                    yield return(child as T);
                }
            }


            /*var typ = element.GetType();
             *
             * if (typeof(Cell).IsAssignableFrom(typeof(T)))
             *  callHandler(element as T);
             *
             * if (typeof(Cell).IsAssignableFrom(typ)) {
             *  var cell = element as Cell;
             *  if (typeof(ViewCell).IsAssignableFrom(typ))
             *      CollectElements<T>((cell as ViewCell).View, callHandler);
             * } else if (typeof(ContentPage).IsAssignableFrom(typ)) {
             *  var page = element as ContentPage;
             *  CollectElements<T>(page.Content, callHandler);
             * } else if (typeof(Layout<View>).IsAssignableFrom(typ)) {
             *  var layout = element as Layout<View>;
             *  foreach (var child in layout.Children)
             *      CollectElements<T>(child, callHandler);
             * } else if (typeof(Layout).IsAssignableFrom(typ)) {
             *  var layout = element as Layout;
             *  foreach (var child in layout.Children)
             *      CollectElements<T>(child, callHandler);
             * } else if (typeof(ITemplatedItemsView<Cell>).IsAssignableFrom(typ)) {
             *  var tiv = element as ITemplatedItemsView<Cell>;
             *  foreach (var cell in tiv.TemplatedItems)
             *      CollectElements<T>(cell, callHandler);
             * }*/
        }
        public virtual void AddChild(XF.Element child, int physicalSiblingIndex)
        {
            if (child is null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            if (child is MasterDetailMasterPageContentPage masterPage)
            {
                MasterDetailPageControl.Master = masterPage;
            }
            else if (child is MasterDetailDetailPageContentPage detailPage)
            {
                MasterDetailPageControl.Detail = detailPage;
            }
            else
            {
                throw new InvalidOperationException($"Unknown child type {child.GetType().FullName} being added to parent element type {GetType().FullName}.");
            }
        }
Ejemplo n.º 38
0
        public override void AddChild(XF.Element child, int physicalSiblingIndex)
        {
            if (child is null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            if (child is TwoPaneViewPane1View pane1View)
            {
                TwoPaneViewControl.Pane1 = pane1View;
            }
            else if (child is TwoPaneViewPane2View pane2View)
            {
                TwoPaneViewControl.Pane2 = pane2View;
            }
            else
            {
                throw new InvalidOperationException($"Unknown child type {child.GetType().FullName} being added to parent element type {GetType().FullName}.");
            }
        }
        /// <summary>
        /// Creates a component of type <typeparamref name="TComponent"/> and adds it as a child of <paramref name="parent"/>.
        /// </summary>
        /// <typeparam name="TComponent"></typeparam>
        /// <param name="host"></param>
        /// <param name="parent"></param>
        public static void AddComponent <TComponent>(this IHost host, XF.Element parent) where TComponent : IComponent
        {
            if (host is null)
            {
                throw new ArgumentNullException(nameof(host));
            }

            if (parent is null)
            {
                throw new ArgumentNullException(nameof(parent));
            }

            var services = host.Services;
            var renderer = services.GetRequiredService <MobileBlazorBindingsRenderer>();

            // TODO: This call is an async call, but is called as "fire-and-forget," which is not ideal.
            // We need to figure out how to get Xamarin.Forms to run this startup code asynchronously, which
            // is how this method should be called.
            renderer.AddComponent <TComponent>(CreateHandler(parent, renderer)).ConfigureAwait(false);
        }
Ejemplo n.º 40
0
		public static Task<Element> GetRealParentAsync(Element element)
		{
			Element parent = element.RealParent;
			if (parent is Application)
				return Task.FromResult<Element>(null);

			if (parent != null)
				return Task.FromResult(parent);

			var tcs = new TaskCompletionSource<Element>();
			EventHandler handler = null;
			handler = (sender, args) =>
			{
				tcs.TrySetResult(element.RealParent);
				element.ParentSet -= handler;
			};
			element.ParentSet += handler;

			return tcs.Task;
		}
		public object ProvideValue(IServiceProvider serviceProvider)
		{
			if (serviceProvider == null) throw new ArgumentNullException("serviceProvider");
			IRootObjectProvider rootObjectProvider = serviceProvider.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider;
			if (rootObjectProvider == null) throw new ArgumentException("serviceProvider does not provide an IRootObjectProvider");
			if (string.IsNullOrEmpty(this.Name)) throw new ArgumentNullException("Name");


			Element nameScope = rootObjectProvider.RootObject as Element;
			Element element = nameScope.FindByName<Element>(this.Name);
			if (element == null) throw new ArgumentNullException(string.Format("Can't find element named '{0}'", this.Name));
			object context = element.BindingContext;

			this.rootElement = element;
			IProvideValueTarget ipvt = (IProvideValueTarget)serviceProvider.GetService(typeof(IProvideValueTarget));
			this.attachedObject = ipvt.TargetObject as BindableObject;
			this.attachedObject.BindingContextChanged += this.OnContextChanged;

			return context ?? new object();
		}
Ejemplo n.º 42
0
        public override void AddChild(XF.Element child, int physicalSiblingIndex)
        {
            if (child is null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            var removedDummyChild = ClearDummyChild();

            switch (child)
            {
            case XF.TemplatedPage childAsTemplatedPage:
                ShellControl.Items.Add(childAsTemplatedPage);     // Implicit conversion
                break;

            case XF.ShellContent childAsShellContent:
                ShellControl.Items.Add(childAsShellContent);     // Implicit conversion
                break;

            case XF.ShellSection childAsShellSection:
                ShellControl.Items.Add(childAsShellSection);     // Implicit conversion
                break;

            case XF.MenuItem childAsMenuItem:
                ShellControl.Items.Add(childAsMenuItem);     // Implicit conversion
                break;

            case XF.ShellItem childAsShellItem:
                ShellControl.Items.Add(childAsShellItem);
                break;

            default:
                throw new NotSupportedException($"Handler of type '{GetType().FullName}' representing element type '{TargetElement?.GetType().FullName ?? "<null>"}' doesn't support adding a child (child type is '{child.GetType().FullName}').");
            }
            // TODO: If this was the first item added, mark it as the current item
            // But this code seems to cause a NullRef...
            //if (removedDummyChild)
            //{
            //    ShellControl.CurrentItem = parentAsShell.Items[0];
            //}
        }
Ejemplo n.º 43
0
        public override void AddChild(XF.Element child, int physicalSiblingIndex)
        {
            if (child is null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            switch (child)
            {
            case XF.TemplatedPage childAsTemplatedPage:
                ShellSectionControl.Items.Add(childAsTemplatedPage);     // Implicit conversion
                break;

            case XF.ShellContent childAsShellContent:
                ShellSectionControl.Items.Add(childAsShellContent);
                break;

            default:
                throw new NotSupportedException($"Handler of type '{GetType().FullName}' representing element type '{TargetElement?.GetType().FullName ?? "<null>"}' doesn't support adding a child (child type is '{child.GetType().FullName}').");
            }
        }
        public void MonitorElement(Element element)
        {
            //System.Windows.Controls.Image img = new System.Windows.Controls.Image();
            //img.
            //var gl = GestureService.GetGestureListener(img);
            //gl.DoubleTap += new EventHandler<GestureEventArgs>(GestureListenerDoubleTap);

            //GestureListener gl = new GestureListener();
            //gl.

            // Windows.UI.Input.GestureRecognizer grTap = new  Windows.UI.Input.GestureRecognizer();
            //grTap.GestureSettings = Windows.UI.Input.GestureSettings.DoubleTap | Windows.UI.Input.GestureSettings.Hold | Windows.UI.Input.GestureSettings.CrossSlide;
            System.Windows.Controls.TextBlock el = new System.Windows.Controls.TextBlock();
            el.ManipulationCompleted
            //Label elbn = new Label();
            //elbn.
            //UIElement elem = el as UIElement;
            //GestureService gs = new GestureService();
            //e
            
        }
Ejemplo n.º 45
0
		public static async Task<Element> FindTemplatedParentAsync(Element element)
		{
			if (element.RealParent is Application)
				return null;

			var skipCount = 0;
			element = await GetRealParentAsync(element);
			while (!Application.IsApplicationOrNull(element))
			{
				var controlTemplated = element as IControlTemplated;
				if (controlTemplated?.ControlTemplate != null)
				{
					if (skipCount == 0)
						return element;
					skipCount--;
				}
				if (element is ContentPresenter)
					skipCount++;
				element = await GetRealParentAsync(element);
			}

			return null;
		}
Ejemplo n.º 46
0
        void DisposeModelAndChildrenRenderers(Xamarin.Forms.Element view)
        {
            IVisualElementRenderer renderer;

            foreach (VisualElement child in view.Descendants())
            {
                renderer = GetRenderer(child);
                child.ClearValue(RendererProperty);

                if (renderer != null)
                {
                    renderer.Dispose();
                }
            }

            renderer = GetRenderer((VisualElement)view);
            if (renderer != null)
            {
                renderer.Dispose();
            }

            view.ClearValue(RendererProperty);
        }
Ejemplo n.º 47
0
		protected override void OnChildAdded(Element child)
		{
			base.OnChildAdded(child);
			var view = child as View;
			if (view != null)
				ComputeConstraintForView(view);
		}
Ejemplo n.º 48
0
		internal override void SetChildInheritedBindingContext(Element child, object context)
		{
			if (ControlTemplate == null)
				base.SetChildInheritedBindingContext(child, context);
		}
Ejemplo n.º 49
0
		double GetCoordinate(Element item, string coordinateName, double coordinate)
		{
			if (item == this)
				return coordinate;
			coordinate += (double)typeof(VisualElement).GetProperty(coordinateName).GetValue(item, null);
			var visualParentElement = item.RealParent as VisualElement;
			return visualParentElement != null ? GetCoordinate(visualParentElement, coordinateName, coordinate) : coordinate;
		}
Ejemplo n.º 50
0
 private static object FindParent(Element target)
 {
     return target.Parent;
 }
Ejemplo n.º 51
0
 protected override void OnChildRemoved(Element child)
 {
     base.OnChildRemoved(child);
     Debug.WriteLine("OnChildRemoved " + child.ToString());
 }
Ejemplo n.º 52
0
 internal void RaiseEvent(Element element, GestureMonitorEventArgs eventArgs)
 {
     if (this.GestureOccured != null)
         this.GestureOccured(element, eventArgs);
 }
Ejemplo n.º 53
0
		internal static bool IsApplicationOrNull(Element element)
		{
			return element == null || element is Application;
		}
Ejemplo n.º 54
0
 private static Element FindParent(Element target)
 {
     return target.ParentView;
 }
 private static IDisposable ObserveParentMember(IBindingMemberInfo bindingMemberInfo, Element o, IEventListener arg3)
 {
     return ParentObserver.GetOrAdd(o).AddWithUnsubscriber(arg3);
 }
 private static object GetParentValue(IBindingMemberInfo bindingMemberInfo, Element target)
 {
     return ParentObserver.GetOrAdd(target).Parent;
 }
Ejemplo n.º 57
0
		protected override void OnChildRemoved(Element child)
		{
			base.OnChildRemoved(child);
			var view = child as View;
			if (view != null)
				view.ComputedConstraint = LayoutConstraint.None;
		}
Ejemplo n.º 58
0
 private ParentObserver(Element view)
 {
     _view = ServiceProvider.WeakReferenceFactory(view);
     _parent = ToolkitExtensions.GetWeakReferenceOrDefault(FindParent(view), Empty.WeakReference, false);
     view.PropertyChanged += OnPropertyChanged;
 }
Ejemplo n.º 59
0
		bool CheckElementBelongsToScrollViewer(Element element)
		{
			return Equals(element, this) || element.RealParent != null && CheckElementBelongsToScrollViewer(element.RealParent);
		}
 private static void SetParentValue(IBindingMemberInfo bindingMemberInfo, Element element, object arg3)
 {
     ParentObserver.GetOrAdd(element).Parent = arg3;
 }