Пример #1
0
        public static UIView DataTemplateToNativeView(this Xamarin.Forms.DataTemplate dt, object bindingContext, Xamarin.Forms.View rootView)
        {
            if (dt == null)
            {
                return(null);
            }
            object content = (dt is DataTemplateSelector dts)
                ? dts.SelectTemplate(bindingContext, rootView)
                : dt.CreateContent();

            View view;

            switch (content)
            {
            case ViewCell viewCell:
                viewCell.Parent         = rootView;
                viewCell.BindingContext = bindingContext;
                view = viewCell.View;
                break;

            case View view1:
                view1.Parent         = rootView;
                view1.BindingContext = bindingContext;
                view = view1;
                break;

            default:
                return(null);
            }

            return(new FormsViewContainer
            {
                View = view
            });
        }
Пример #2
0
        void OnHeaderOrFooterChanged(ref Element storage, string property, object dataObject, DataTemplate template, bool templateChanged)
        {
            if (dataObject == null)
            {
                if (!templateChanged)
                {
                    OnPropertyChanging(property);
                    storage = null;
                    OnPropertyChanged(property);
                }

                return;
            }

            if (template == null)
            {
                var view = dataObject as Element;
                if (view == null || view is Page)
                {
                    view = new Label {
                        Text = dataObject.ToString()
                    }
                }
                ;

                view.Parent = this;
                OnPropertyChanging(property);
                storage = view;
                OnPropertyChanged(property);
            }
            else if (storage == null || templateChanged)
            {
                OnPropertyChanging(property);
                storage = template.CreateContent() as Element;
                if (storage != null)
                {
                    storage.BindingContext = dataObject;
                    storage.Parent         = this;
                }
                OnPropertyChanged(property);
            }
            else
            {
                storage.BindingContext = dataObject;
            }
        }
Пример #3
0
        public static void OnViewTemplateChanged(
            DataTemplate newViewTemplate,
            ref View localViewRef,
            object currentViewData,
            Action <Element> OnChildRemoved,
            Action <Element> OnChildAdded,
            Shell shell)
        {
            View newContentView = currentViewData as View;

            if (newViewTemplate != null)
            {
                newContentView = (View)newViewTemplate.CreateContent(newViewTemplate, shell);
            }

            SetView(ref localViewRef,
                    newContentView,
                    OnChildRemoved,
                    OnChildAdded);
        }
Пример #4
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;
     }
 }
        private void SetupContentGrid()
        {
            _contentGrid = new Grid {
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                RowDefinitions = {
                    new RowDefinition { Height = Device.OnPlatform(32,10,0) },
                    new RowDefinition { Height = 50 },
                    new RowDefinition { Height = Device.OnPlatform(200,220,0) },
                    new RowDefinition { Height = 50 },
                    new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
                    new RowDefinition { Height = 40 },
                },
                IsVisible = false
            };

            _contentGrid.Children.Add(new StackLayout { Padding = new Thickness(20, 0, 0, 0), Children = { new Label { Text = "Upcoming Events", TextColor = Color.White, FontSize = 24, VerticalOptions = LayoutOptions.CenterAndExpand } } }, 0, 1);
            _contentGrid.Children.Add(new StackLayout { Padding = new Thickness(20, 0, 0, 0), Children = { new Label { Text = "Recent Messages", TextColor = Color.White, FontSize = 24, VerticalOptions = LayoutOptions.CenterAndExpand } } }, 0, 3);

            _calendarEventListView = new NoHighlightListView { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill, BackgroundColor = Color.Transparent };
            var calendarEventItemTemplate = new DataTemplate(() => new CalendarEventItemTemplate());
            calendarEventItemTemplate.CreateContent();
            _calendarEventListView.SeparatorVisibility = SeparatorVisibility.None;
            _calendarEventListView.ItemsSource = _calendarEvents;
            _calendarEventListView.ItemTemplate = calendarEventItemTemplate;
            _calendarEventListView.HasUnevenRows = true;
            _calendarEventListView.ItemTapped += (sender, e) => {
                if (e.Item == null) {
                    return;
                }
                ((ListView)sender).SelectedItem = null;
            };
            _contentGrid.Children.Add(_calendarEventListView, 0, 2);

            _messageListView = new NoHighlightListView { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill, BackgroundColor = Color.Transparent };
            var messageItemTemplate = new DataTemplate(() => new MessageItemTemplate());
            messageItemTemplate.CreateContent();
            _messageListView.SeparatorVisibility = SeparatorVisibility.None;
            _messageListView.ItemsSource = _messages;
            _messageListView.ItemTemplate = messageItemTemplate;
            _messageListView.HasUnevenRows = true;
            _messageListView.ItemTapped += (sender, e) => {
                if (e.Item == null) {
                    return;
                }
                ((ListView)sender).SelectedItem = null;
            };
            _contentGrid.Children.Add(_messageListView, 0, 4);

            Button refreshButton = new Button { Text = "Refresh", TextColor = Color.White, FontSize = 18, VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.EndAndExpand, BackgroundColor = Color.Transparent };
            refreshButton.Clicked += RefreshButton_Clicked;
            _contentGrid.Children.Add(new StackLayout { Orientation = StackOrientation.Horizontal, Children = { refreshButton }, Padding = new Thickness(0,0,10,0) }, 0, 5);

            _backgroundGrid.Children.Add(_contentGrid, 0, 0);
        }