Exemple #1
0
 public void RecycleCell(object data, DataTemplate dataTemplate, VisualElement parent)
 {
     if (_viewCell == null)
     {
         _viewCell = (dataTemplate.CreateContent() as FastGridCell);
         _viewCell.BindingContext = data;
         _viewCell.Parent         = parent;
         _viewCell.PrepareCell(new Size(Bounds.Width, Bounds.Height));
         _originalBindingContext = _viewCell.BindingContext;
         var renderer = RendererFactory.GetRenderer(_viewCell.View);
         _view = renderer.NativeView;
         _view.AutoresizingMask = UIViewAutoresizing.All;
         _view.ContentMode      = UIViewContentMode.ScaleToFill;
         ContentView.AddSubview(_view);
         return;
     }
     else if (data == _originalBindingContext)
     {
         _viewCell.BindingContext = _originalBindingContext;
     }
     else
     {
         _viewCell.BindingContext = data;
     }
 }
Exemple #2
0
        private void UpdateContent()
        {
            return;

            ContentView cv;

            if (BorderElement.Content == null)
            {
                return;
            }

            if (childView != null)
            {
                RemoveView(childView);
            }

            var contentRenderer = RendererFactory.GetRenderer(BorderElement.Content);

            childView = contentRenderer.ViewGroup;
            childView.LayoutParameters = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.MatchParent);

            AddView(childView);

            // AddView (new Android.Widget.Button (Context) { Text = "AAA" }, new ViewGroup.LayoutParams(300, 300));
        }
        /// <summary>
        /// Managest adding and removing the android viewgroup to our actual swiperefreshlayout
        /// </summary>
        void UpdateContent()
        {
            if (RefreshView.Content == null)
            {
                return;
            }

            if (packed != null)
            {
                RemoveView(packed.ViewGroup);
            }

            packed = RendererFactory.GetRenderer(RefreshView.Content);

            try
            {
                RefreshView.Content.SetValue(RendererProperty, packed);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Unable to sent renderer property, maybe an issue: " + ex);
            }

            AddView(packed.ViewGroup, LayoutParams.MatchParent);
        }
        /// <summary>
        /// Gets the cell.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <param name="convertView">The convert view.</param>
        /// <param name="parent">The parent.</param>
        /// <returns>Android.Views.View.</returns>
        public global::Android.Views.View GetCell(int position, global::Android.Views.View convertView, ViewGroup parent)
        {
            var item           = this.Element.ItemsSource.Cast <object>().ElementAt(position);
            var viewCellBinded = (Element.ItemTemplate.CreateContent() as ViewCell);

            viewCellBinded.BindingContext = item;
            var view = RendererFactory.GetRenderer(viewCellBinded.View);

            // Platform.SetRenderer (viewCellBinded.View, view);
            view.ViewGroup.LayoutParameters = new  Android.Widget.GridView.LayoutParams(Convert.ToInt32(this.Element.ItemWidth), Convert.ToInt32(this.Element.ItemHeight));
            view.ViewGroup.SetBackgroundColor(global::Android.Graphics.Color.Blue);
            return(view.ViewGroup);
            //                this.AddView (this.view.ViewGroup);

            //            GridViewCellRenderer render = new GridViewCellRenderer ();
            //
            //            return render.GetCell (viewCellBinded, convertView, parent, this.Context);;
            //          //  view.LayoutParameters = new GridView.LayoutParams (this.Element.ItemWidth,this.Element.ItemHeight);
            //            return view;
            //            ImageView imageView;
            //
            //            if (convertView == null) {  // if it's not recycled, initialize some attributes
            //                imageView = new ImageView (Forms.Context);
            //                imageView.LayoutParameters = new GridView.LayoutParams (85, 85);
            //                imageView.SetScaleType (ImageView.ScaleType.CenterCrop);
            //                imageView.SetPadding (8, 8, 8, 8);
            //            } else {
            //                imageView = (ImageView)convertView;
            //            }
            //            var imageBitmap = GetImageBitmapFromUrl("http://xamarin.com/resources/design/home/devices.png");
            //            imageView.SetImageBitmap(imageBitmap);
            //            return imageView;
        }
Exemple #5
0
        private UIView CreateFrameUIView(RoundedFrame roundedFrame)
        {
            // Shadows on rounded rect require 2 views, one for the rounded rect, and one for the shadow
            childView = new UIView()
            {
                Layer =
                {
                    CornerRadius = (System.nfloat)roundedFrame.CornerRadius,
                    BorderColor  = roundedFrame.OutlineColor.ToCGColor(),
                    BorderWidth  = (System.nfloat)roundedFrame.OutlineWidth,
                },
                AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight,
            };

            var shadowView = new UIView();

            shadowView.Add(childView);
            shadowView.Layer.SetShadowPropertiesOnLayer(roundedFrame.HasShadow);

            // Frame should be behind any of the Content views // MO: I'm not sure if this is working
            this.SendSubviewToBack(shadowView);

            // http://forums.xamarin.com/discussion/30513/how-to-add-the-content-of-a-frame-as-a-subview-in-an-uiview-add-views-as-subviews-of-uiview
            // BUT: does this end up rendering twice?
            if (roundedFrame.Content != null)
            {
                var rend = RendererFactory.GetRenderer(roundedFrame.Content);
                shadowView.Add(rend.NativeView);
            }

            return(shadowView);
        }
        /// <summary>
        /// Raises the element changed event.
        /// </summary>
        /// <param name="e">E.</param>
        protected override void OnElementChanged(ElementChangedEventArgs <Refractored.XamForms.PullToRefresh.PullToRefreshLayout> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null || Element == null)
            {
                return;
            }



            refreshControl = new UIRefreshControl();

            refreshControl.ValueChanged += OnRefresh;

            var packed = RendererFactory.GetRenderer(Element.Content);

            Element.Content.SetValue(RendererProperty, packed);

            SetNativeControl(packed.NativeView);
            try
            {
                TryInsertRefresh(Control);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("View is not supported in PullToRefreshLayout: " + ex);
            }


            UpdateColors();
            UpdateIsRefreshing();
            UpdateIsSwipeToRefreshEnabled();
        }
Exemple #7
0
        void ChangePage(Page page)
        {
            //TODO handle current page
            if (page != null)
            {
                var parentPage = Element.GetParentPage();
                page.Parent = parentPage;

                var existingRenderer = page.GetRenderer();
                if (existingRenderer == null)
                {
                    var renderer = RendererFactory.GetRenderer(page);
                    page.SetRenderer(renderer);
                    existingRenderer = page.GetRenderer();
                }
                _contentNeedsLayout = true;
                SetNativeControl(existingRenderer.ViewGroup);
                Invalidate();
                //TODO update the page
                _currentPage = page;
            }
            else
            {
                //TODO - update the page
                _currentPage = null;
            }

            if (_currentPage == null)
            {
                //have to set somethign for android not to get pissy
                var view = new Android.Views.View(this.Context);
                view.SetBackgroundColor(Element.BackgroundColor.ToAndroid());
                SetNativeControl(view);
            }
        }
Exemple #8
0
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            var ct     = (ContentControl)element;
            var render = RendererFactory.GetRenderer((View)item);

            ct.Content = render;//render == render.ContainerElement;
        }
Exemple #9
0
        void element_ChildAdded(object sender, ElementEventArgs e)
        {
            var            visualElement = (VisualElement)e.Element;
            IWinRTRenderer renderer      = RendererFactory.GetRenderer(visualElement);

            visualElement.SetRenderer(renderer);
            SetChildren((UIElement)renderer);
        }
Exemple #10
0
 private IEnumerable <UIView> GetChildrenViews()
 {
     foreach (var v in this.Element.Children)
     {
         var render = RendererFactory.GetRenderer(v);
         yield return(render.NativeView);
     }
 }
Exemple #11
0
        /// <summary>
        /// Renders the specified <see cref="MvcComponentBase" /> to the current WebForms view.
        /// </summary>
        /// <param name="helper">The HTML helper instance that this method extends.</param>
        /// <param name="component">The <see cref="MvcComponentBase" /> to render.</param>
        public static void KrystalwareWebForms(this HtmlHelper helper, MvcComponentBase component)
        {
            IComponentRenderer renderer = RendererFactory.GetRenderer(component);

            renderer.Register(component);

            using (HtmlTextWriter w = new HtmlTextWriter(helper.ViewContext.Writer))
                renderer.Render(component, w);
        }
        public NativeCell(NSString cellId, FastCell fastCell) : base(UITableViewCellStyle.Default, cellId)
        {
            _fastCell = fastCell;
            _fastCell.PrepareCell();
            _originalBindingContext = fastCell.BindingContext;
            var renderer = RendererFactory.GetRenderer(fastCell.View);

            _view = renderer.NativeView;
            ContentView.AddSubview(_view);
        }
        public NativeCell(Android.Content.Context context, FastCell fastCell) : base(context)
        {
            FastCell = fastCell;
            fastCell.PrepareCell();
            var renderer = RendererFactory.GetRenderer(fastCell.View);

            this.AddView(renderer.ViewGroup);
            //			_view = renderer.NativeView;
            //			ContentView.AddSubview (_view);
        }
Exemple #14
0
        protected T GetInitializedElement <T> (View view)
            where T : class, IVisualElementRenderer
        {
            var renderer = RendererFactory.GetRenderer(view) as T;
            var parent   = new UIView();

            parent.AddSubview(renderer.NativeView);

            return(renderer);
        }
Exemple #15
0
 private IEnumerable <AV.View> GetChildrenViews()
 {
     foreach (var v in this.Element.Children)
     {
         var render = RendererFactory.GetRenderer(v);
         var c      = new AW.FrameLayout(this.Context);
         c.SetBackgroundColor(Color.Blue.ToAndroid());
         c.AddView(render.ViewGroup, LayoutParams.MatchParent, LayoutParams.MatchParent);
         yield return(c);
     }
 }
Exemple #16
0
        /// <summary>
        /// Gets the or create renderer.
        /// </summary>
        /// <returns>The or create renderer.</returns>
        /// <param name="source">Source.</param>
        public static IVisualElementRenderer GetOrCreateRenderer(VisualElement source)
        {
            var renderer = RendererHelper.GetRenderer(source);

            if (renderer == null)
            {
                renderer = RendererFactory.GetRenderer(source);
                RendererHelper.SetRenderer(source, renderer);
                renderer = RendererHelper.GetRenderer(source);
            }
            return(renderer);
        }
Exemple #17
0
        /// <summary>
        /// Gets the or create renderer.
        /// </summary>
        /// <returns>The or create renderer.</returns>
        /// <param name="source">Source.</param>
        public static IVisualElementRenderer GetOrCreateRenderer(this VisualElement source)
        {
            var renderer = source.GetRenderer();

            if (renderer == null)
            {
                renderer = RendererFactory.GetRenderer(source);
                source.SetRenderer(renderer);
                renderer = source.GetRenderer();
            }
            return(renderer);
        }
        private void UpdateView()
        {
            if (this.view != null)
            {
                this.view.RemoveFromSuperview();
            }
            this.view = RendererFactory.GetRenderer(this.viewCell.View).NativeView;
            this.view.AutoresizingMask = UIViewAutoresizing.All;
            this.view.ContentMode      = UIViewContentMode.ScaleToFill;

            this.AddSubview(this.view);
        }
Exemple #19
0
        /// <summary>
        /// Attempts to get the <see cref="IVisualElementRenderer" /> for a given <see cref="BindableObject" />.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns>Returns a <see cref="IVisualElementRenderer" />.</returns>
        public static IVisualElementRenderer GetRenderer(this VisualElement element)
        {
            var renderer = element.GetValue(RendererProperty) as IVisualElementRenderer;

            if (renderer == null)
            {
                renderer = RendererFactory.GetRenderer(element);
                element.SetValue(RendererProperty, renderer);
            }

            return(renderer);
        }
		public override Java.Lang.Object InstantiateItem ( ViewGroup container , int position ) {
			ContentPage contentPage = page.Children [ position ];
			if ( GetRenderer ( contentPage ) == null ) {
				SetRenderer ( contentPage , RendererFactory.GetRenderer ( contentPage ) );
			}
			IVisualElementRenderer renderer = GetRenderer ( contentPage );
			renderer.ViewGroup.RemoveFromParent ();
			PageContainer pageContainer = new PageContainer ( context , renderer );
			container.AddView ( pageContainer );
			return
					new ObjectJavaBox <Tuple <ViewGroup , Page , int>> (
							new Tuple <ViewGroup , Page , int> ( pageContainer , contentPage , position ) );
		}
Exemple #21
0
        public override void WillMoveToParentViewController(UIViewController parent)
        {
            base.WillMoveToParentViewController(parent);

            var page = (ExtendedContentPage)Element;

            var renderer = RendererFactory.GetRenderer(page.TitleView);
            var view     = renderer.NativeView;

            view.SizeToFit();

            parent.NavigationItem.TitleView = view.Subviews[0];
        }
    public static ViewGroup ConvertFormsToNative(Xamarin.Forms.View view, Rectangle size)
    {
        var vRenderer = RendererFactory.GetRenderer(view);
        var viewGroup = vRenderer.ViewGroup;

        vRenderer.Tracker.UpdateLayout();
        var layoutParams = new ViewGroup.LayoutParams((int)size.Width, (int)size.Height);

        viewGroup.LayoutParameters = layoutParams;
        view.Layout(size);
        viewGroup.Layout(0, 0, (int)view.WidthRequest, (int)view.HeightRequest);
        return(viewGroup);
    }
Exemple #23
0
        public override MonoTouch.UIKit.UITableViewCell GetCell(Cell item, MonoTouch.UIKit.UITableView tv)
        {
            AccessoryViewCell viewCell = item as AccessoryViewCell;
            var nativeCell             = base.GetCell(item, tv);

            var frame      = new RectangleF(0, 0, (float)viewCell.AccessoryView.WidthRequest, (float)viewCell.AccessoryView.HeightRequest);
            var nativeView = RendererFactory.GetRenderer(viewCell.AccessoryView).NativeView;

            nativeView.Frame         = frame;
            nativeView.Bounds        = frame;
            nativeCell.AccessoryView = nativeView;

            return(nativeCell);
        }
Exemple #24
0
        /// <summary>
        /// Renders the specified <see cref="MvcComponentBase" /> and returns the output for a Razor view.
        /// </summary>
        /// <param name="helper">The HTML helper instance that this method extends.</param>
        /// <param name="component">The <see cref="MvcComponentBase" /> to render.</param>
        public static MvcHtmlString KrystalwareRazor(this HtmlHelper helper, MvcComponentBase component)
        {
            IComponentRenderer renderer = RendererFactory.GetRenderer(component);

            renderer.Register(component);

            using (StringWriter s = new StringWriter())
            {
                using (HtmlTextWriter w = new HtmlTextWriter(s))
                    renderer.Render(component, w);

                return(MvcHtmlString.Create(s.ToString()));
            }
        }
        public WinRTRendererControl(View view)
        {
            _view = view;
            var renderer = RendererFactory.GetRenderer(view);

            view.SetRenderer(renderer);
            base.Content = renderer;
            var uiElement = renderer as FrameworkElement;

            if (uiElement != null)
            {
                uiElement.Loaded += (s, e) => InvalidateMeasure();
            }
        }
Exemple #26
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            Page page = value as Page;

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

            IWinRTRenderer renderer = RendererFactory.GetRenderer(page);

            page.SetRenderer(renderer);
            return(renderer);
        }
Exemple #27
0
        private void PackChild()
        {
            if (Element.Content == null)
            {
                return;
            }
            if (Element.Content.GetRenderer() == null)
            {
                Element.Content.SetRenderer(RendererFactory.GetRenderer(Element.Content));
            }
            var renderer = Element.Content.GetRenderer() as System.Windows.UIElement;

            Control.Child = renderer;
        }
        public void InputWithoutAnythingSpecialReturnsBasicInputElement()
        {
            string block = "input";
            var nodes = Parse(block);

            IRendererFactory factory = new RendererFactory();

            factory.RegisterFactory("input", new InputRenderer());
            var renderer = factory.GetRenderer(nodes.Children.First().BlockName);

            var result = renderer.Render(nodes.Children.First(), null);

            Assert.AreEqual("<input />", result);
        }
        public void InputWithAttributsReturnsElementWithAttributes()
        {
            string block = "input[attr=\"value\"]";

            var nodes = Parse(block);

            IRendererFactory factory = new RendererFactory();

            factory.RegisterFactory("input", new InputRenderer());
            var renderer = factory.GetRenderer(nodes.Children.First().BlockName);

            var result = renderer.Render(nodes.Children.First(), null);

            Assert.AreEqual("<input attr=\"value\" />", result);
        }
Exemple #30
0
    protected override global::Android.Views.View GetCellCore(Cell item, global::Android.Views.View convertView, ViewGroup parent, Context context)
    {
        ViewCell viewCell = (ViewCell)item;

        cxGridViewCellRenderer.ViewCellContainer viewCellContainer = convertView as cxGridViewCellRenderer.ViewCellContainer;
        if (viewCellContainer != null)
        {
            viewCellContainer.Update(viewCell);
            return(viewCellContainer);
        }

        IVisualElementRenderer renderer = RendererFactory.GetRenderer(viewCell.View);

        return(new cxGridViewCellRenderer.ViewCellContainer(context, renderer, viewCell, parent));
    }
Exemple #31
0
 public void MonitorView(View view)
 {
     view.PropertyChanged += (_, propArgs) =>
     {
         // subscribe to UIElement events when the attached property Renderer is set
         if (propArgs.PropertyName == "Platform.RendererProperty.PropertyName")
         {
             GestureRenderer renderer = RendererFactory.GetRenderer(view) as GestureRenderer;
             if (renderer != null)
             {
                 renderer.SetMonitor(this);
             }
         }
     };
 }
        public IVisualElementRenderer Convert(Xamarin.Forms.View source, Xamarin.Forms.VisualElement valid)
        {
            IVisualElementRenderer render = (IVisualElementRenderer)source.GetValue(RendererProperty);

            if (render == null)
            {
                render = RendererFactory.GetRenderer(source);
                source.SetValue(RendererProperty, render);
                var p = PlatformProperty.GetValue(valid);
                PlatformProperty.SetValue(source, p);
                IsPlatformEnabledProperty.SetValue(source, true);
            }

            return(render);
        }