public GridViewCellTemplate()
        {
            //			var thumbnailImage = new Image () {
            //				HorizontalOptions = LayoutOptions.Center,
            //				VerticalOptions = LayoutOptions.Center,
            //				BackgroundColor = ColorConstants.SemiOpaqueBackground,
            //				WidthRequest = UIConstants.GetGridViewItemWidths (),
            //				HeightRequest = UIConstants.GetGridViewItemHeights () - 40,
            //				Source = "New/foldedpdf.png"
            //			};
            //			thumbnailImage.SetBinding (Image.SourceProperty, new Binding ("ThumbPath", converter: new NoCacheConverter ()));

            var thumbnailImage = new CachedImage () {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions = LayoutOptions.CenterAndExpand,
                WidthRequest = UIConstants.GetGridViewItemWidths (),
                HeightRequest = UIConstants.GetGridViewItemHeights () - 40,
                BackgroundColor = ColorConstants.SemiOpaqueBackground,

                CacheDuration = TimeSpan.FromDays (30),
                DownsampleHeight = UIConstants.GetThumbnailHeight () - 100,
                RetryCount = 3,
                RetryDelay = 250,
                TransparencyEnabled = false,
                // Shown after loading error occurs:
                ErrorPlaceholder = Device.OnPlatform (iOS: "corningimages/loading.png", Android: "loading.png", WinPhone: "loading.png"),
                // Shown before targe image is loaded:
                LoadingPlaceholder = Device.OnPlatform (iOS: "corningimages/loading.png", Android: "loading.png", WinPhone: "loading.png"),
            };

            thumbnailImage.SetBinding (CachedImage.SourceProperty, new Binding ("ThumbPath", converter: new NoCacheConverter ()));

            var titleLabel = new CustomLabel2 () {
                FontSize = UIConstants.GetGridViewFontSize (),
                TextColor = Color.White,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.StartAndExpand,
                WidthRequest = UIConstants.GetGridViewItemWidths (),
                HeightRequest = 40,
            };
            titleLabel.SetBinding (Label.TextProperty, "FileName");

            Device.OnPlatform (
                iOS: () => {
                    this.View = new StackLayout {
                        WidthRequest = UIConstants.GetGridViewItemWidths (),
                        HeightRequest = UIConstants.GetGridViewItemHeights (),
                        Orientation = StackOrientation.Vertical,
                        Children = {
                            thumbnailImage,
                            titleLabel
                        }
                    };
                },
                Android: () => {
                    this.View = new AbsoluteLayout {
                        WidthRequest = UIConstants.GetGridViewItemWidths (),
                        HeightRequest = UIConstants.GetGridViewItemHeights (),
                        //Orientation = StackOrientation.Vertical,
                        Children = {
                            thumbnailImage,
                            titleLabel
                        }
                    };
                }
            );
        }
        protected override void OnBindingContextChanged()
        {
            base.OnBindingContextChanged ();

            dynamic c = BindingContext;

            Grid details = new Grid {
                //Padding = 5,
                VerticalOptions = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                RowDefinitions = {
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },
                },
                ColumnDefinitions = {
                    new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
                }
            };

            var thumbnailImage = new CachedImage {
                Aspect = Aspect.AspectFit,
                Source = c.ThumbPath,
                HorizontalOptions =
                    LayoutOptions.CenterAndExpand,
                VerticalOptions =
                    LayoutOptions.CenterAndExpand,
                HeightRequest = 183,
                WidthRequest = 183,
                BackgroundColor = ColorConstants.SemiOpaqueBackground,
                CacheDuration = TimeSpan.FromDays (30),
                DownsampleHeight = 80,
                RetryCount = 3,
                RetryDelay = 250,
                TransparencyEnabled = false,
                ErrorPlaceholder = Device.OnPlatform (iOS: "corningimages/loading.png", Android: "loading.png", WinPhone: "loading.png"),
                LoadingPlaceholder = Device.OnPlatform (iOS: "corningimages/loading.png", Android: "loading.png", WinPhone: "loading.png"),
            };

            var title = new CustomLabel2 () {
                Text = c.FileName,
                FontSize = UIConstants.GetGridViewFontSize (),
                TextColor = Color.White,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.End,
                WidthRequest = 183,
                HeightRequest = 40,
            };

            details.Children.Add (thumbnailImage, 0, 0);
            details.Children.Add (title, 0, 1);

            var layout = new StackLayout {
                Padding = 0,
                //Orientation  = LayoutOptions.,
                Children = {
                    details
                }
            };

            View = layout;
        }
        public DocumentsCellTemplate()
        {
            var publishLabel = new Label () {
                FontSize = UIConstants.GetHomePageFontSize (),
                TextColor = Color.White,
                HorizontalOptions = LayoutOptions.StartAndExpand,
            };
            publishLabel.SetBinding (Label.TextProperty, new Binding ("PublicationDate", converter: new DateConverter ()));

            var nameLabel = new CustomLabel () {
                FontSize = UIConstants.GetHomePageFontSize (),
                TextColor = Color.White,
                FontAttributes = FontAttributes.Bold,
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions = LayoutOptions.StartAndExpand,
            };
            nameLabel.SetBinding (Label.TextProperty, "FileName");

            var descriptionLabel = new CustomLabel2 () {
                FontSize = UIConstants.GetHomePageFontSize (),
                TextColor = Color.White,
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions = LayoutOptions.StartAndExpand,
            };
            descriptionLabel.SetBinding (Label.TextProperty, "Description");

            Device.OnPlatform (iOS: () => {
                nameLabel.LineBreakMode = LineBreakMode.TailTruncation;
                descriptionLabel.LineBreakMode = LineBreakMode.TailTruncation;
            });

            var thumbnailImage = new CachedImage () {
                HorizontalOptions = LayoutOptions.StartAndExpand,
                VerticalOptions = LayoutOptions.StartAndExpand,
                HeightRequest = UIConstants.GetThumbnailHeight (),
                WidthRequest = UIConstants.GetThumbnailWidth (),
                BackgroundColor = ColorConstants.SemiOpaqueBackground,

                CacheDuration = TimeSpan.FromDays (30),
                DownsampleHeight = UIConstants.GetThumbnailHeight () - 100,
                RetryCount = 3,
                RetryDelay = 250,
                TransparencyEnabled = false,
                ErrorPlaceholder = Device.OnPlatform (iOS: "corningimages/loading.png", Android: "loading.png", WinPhone: "loading.png"),
                LoadingPlaceholder = Device.OnPlatform (iOS: "corningimages/loading.png", Android: "loading.png", WinPhone: "loading.png")

            };

            thumbnailImage.SetBinding (CachedImage.SourceProperty, new Binding ("ThumbPath", converter: new NoCacheConverter ()));

            var downloadLabel = new Label () {
                FontSize = UIConstants.GetHomePageFontSize (),
                TextColor = Color.White,
                HorizontalOptions = LayoutOptions.StartAndExpand,
            };
            downloadLabel.SetBinding (Label.TextProperty, new Binding ("DownloadDate", converter: new DownloadDateConverter ()));

            //Read Online Button
            var readOnline = new Button () {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions = LayoutOptions.Center,
                BackgroundColor = Color.FromHex ("#006699"),
                TextColor = Color.White,
                HeightRequest = UIConstants.GetButtonHeight (),
                WidthRequest = UIConstants.GetButtonWidth (),
            };

            readOnline.SetBinding (Button.TextProperty, new Binding ("CategoryCode", converter: new OfflineTextConverter ()));
            readOnline.SetBinding (Button.CommandParameterProperty, new Binding ("."));

            readOnline.Clicked += (sender, e) => {

                var btn = ((Button)sender);

                var fileItem = (Downloads)btn.CommandParameter;

                if (fileItem.MimeType.StartsWith ("mp4")) {
                    Device.OnPlatform (
                        iOS: () => {
                            var page = (Page)Activator.CreateInstance (typeof(DownloadViewer), fileItem);
                            this.ParentView.Navigation.PushAsync (page, true);
                        },
                        Android: () => {
                            var page = (Page)Activator.CreateInstance (typeof(AndroidVideoPlayer), fileItem);
                            this.ParentView.Navigation.PushAsync (page, true);
                        }
                    );
                } else {
                    var pdfService = DependencyService.Get<IPdfService> ();
                    if (pdfService == null)
                        return;

                    pdfService.OpenPDF (LibraryType.MyDocuments, fileItem.FilePath, fileItem.FileName, 0, null);
                }

            };

            //Download Button
            var download = new Button () {
                Text = Translation.Localize ("DeleteText"),
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions = LayoutOptions.Center,
                BackgroundColor = Color.FromHex ("#006699"),
                TextColor = Color.White,
                HeightRequest = UIConstants.GetButtonHeight (),
                WidthRequest = UIConstants.GetButtonWidth (),
            };
            download.SetBinding (Button.CommandParameterProperty, new Binding ("."));

            download.Clicked += async (sender, e) => {

                var btn = ((Button)sender);
                //download.IsEnabled = false;
                var fileItem = (Downloads)btn.CommandParameter;
                var parent = (MyDocumentsView)this.ParentView.ParentView.Parent;

                var textToDisplay =
                    fileItem.MimeType.StartsWith ("mp4")
                    ? Translation.Localize ("DeleteVideoMessage")
                    : Translation.Localize ("DeleteDocumentMessage");

                var confirm = await parent.DisplayAlert ("", textToDisplay, Translation.Localize ("Yes"), Translation.Localize ("No"));

                if (confirm) {
                    var deleteService = DependencyService.Get<IDeleteService> ();
                    if (deleteService == null)
                        return;

                    deleteService.DeleteFile (fileItem.FilePath, (bool completed) => {
                        if (completed == true) {
                            var ViewModel = (MyDocumentsViewModel)this.Parent.BindingContext;
                            ViewModel.DocFileID = fileItem.Id;
                            ViewModel.DeleteDocumentsCommand.Execute (null);
                        }
                    });

                }
            };

            Grid grid = new Grid {
                Padding = 5,
                VerticalOptions = LayoutOptions.Center,
                RowDefinitions = {
                    new RowDefinition { Height = GridLength.Auto },
                },
                ColumnDefinitions = {
                    new ColumnDefinition { Width = GridLength.Auto },
                    new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
                }
            };

            Grid details = new Grid {
                Padding = 5,
                VerticalOptions = LayoutOptions.Start,
                RowDefinitions = {
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },
                },
                ColumnDefinitions = {
                    new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },

                }
            };

            details.Children.Add (publishLabel, 0, 0);
            details.Children.Add (nameLabel, 0, 1);
            details.Children.Add (descriptionLabel, 0, 2);
            details.Children.Add (readOnline, 0, 3);
            details.Children.Add (download, 0, 4);

            Grid leftdetails = new Grid {
                Padding = 5,
                VerticalOptions = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                RowDefinitions = {
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },
                },
                ColumnDefinitions = {
                    new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
                }
            };

            leftdetails.Children.Add (thumbnailImage, 0, 0);
            leftdetails.Children.Add (downloadLabel, 0, 1);

            grid.Children.Add (leftdetails, 0, 0);
            grid.Children.Add (details, 1, 0);

            var frame = new Frame {
                OutlineColor = Color.FromRgba (255, 255, 255, 0.5),
                HasShadow = true,
                HorizontalOptions = LayoutOptions.Center,
                BackgroundColor = Color.FromRgba (255, 255, 255, 0.1),
                VerticalOptions = LayoutOptions.Center,
                Padding = 5,
            };

            Device.OnPlatform (
                iOS: () => {
                    frame.Content = new StackLayout {
                        Padding = 0,
                        Children = {
                            grid
                        }
                    };
                },
                Android: () => {
                    frame.Content = new AbsoluteLayout {
                        Padding = 0,
                        Children = {
                            grid
                        }
                    };
                }
            );

            this.View = frame;
        }