public DashWidgetView(DashSquare square)
        {
            RelativeLayout layout = new RelativeLayout();

            var tapGestureRecognizer = new TapGestureRecognizer();

            tapGestureRecognizer.Tapped += (s, e) => {
                EventHandler <WidgetTappedEventArgs> handler = Tapped;
                handler?.Invoke(this, new WidgetTappedEventArgs(square));
            };

            layout.GestureRecognizers.Add(tapGestureRecognizer);

            var backgroundImage = new CachedImage()
            {
                Source = new UriImageSource
                {
                    CachingEnabled = true,
                    CacheValidity  = new TimeSpan(5, 0, 0, 0),
                    Uri            = new Uri(square.PreviewImage)
                },
                Aspect           = Aspect.AspectFill,
                InputTransparent = false,

                CacheDuration      = new TimeSpan(5, 0, 0, 0),
                LoadingPlaceholder = "placeholder.jpg"
            };

            layout.Children.Add(backgroundImage,
                                Constraint.Constant(0),
                                Constraint.Constant(0),
                                Constraint.RelativeToParent((parent) => parent.Width),
                                Constraint.RelativeToParent((parent) => parent.Height));

            this.Padding = new Thickness(10, 10);
            Content      = layout;
        }
Ejemplo n.º 2
0
        public ActionPage()
        {
            InitializeComponent();
            NavigationPage.SetHasNavigationBar(this, false);

            var returnComman = new Command(() =>
            {
                Navigation.PopAsync(true);
            });

            ImageStackLayout.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = returnComman
            });

            RelativeLayout layout = new RelativeLayout();

            var backgroundImage = new CachedImage()
            {
                Aspect            = Aspect.AspectFit,
                InputTransparent  = false,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,

                CacheDuration      = new TimeSpan(5, 0, 0, 0),
                LoadingPlaceholder = "placeholder.jpg"
            };

            layout.Children.Add(backgroundImage,
                                Constraint.Constant(0),
                                Constraint.Constant(0),
                                Constraint.RelativeToParent((parent) => parent.Width),
                                Constraint.RelativeToParent((parent) => parent.Height));

            ImageStackLayout.Children.Add(layout);

            MessagingCenter.Subscribe <ActionPage, DashSquare>(this, "Hi", (page, dashSquare) =>
            {
                CurrentItem = dashSquare;

                backgroundImage.Source = new UriImageSource
                {
                    CachingEnabled = true,
                    CacheValidity  = new TimeSpan(5, 0, 0, 0),
                    Uri            = new Uri(CurrentItem.BigImage)
                };

                var indicator = new ActivityIndicator
                {
                    Color             = Color.FromHex("#009d48"),
                    BackgroundColor   = Color.Transparent,
                    VerticalOptions   = LayoutOptions.CenterAndExpand,
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                };
                layout.Children.Add(indicator,
                                    Constraint.Constant(0),
                                    Constraint.Constant(0),
                                    Constraint.RelativeToParent((parent) => parent.Width),
                                    Constraint.RelativeToParent((parent) => parent.Height));

                indicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsLoading");
                indicator.BindingContext = backgroundImage;
            });
        }