예제 #1
0
        public ColouredFrame(double height) : base()
        {
            var inner = height;

            _colorData = new RandomColorData();
            var layout = new AbsoluteLayout()
            {
                WidthRequest  = inner,
                HeightRequest = inner,
            };

            _loadingIndicator = new ActivityIndicator()
            {
                IsRunning     = true,
                IsVisible     = false,
                WidthRequest  = inner,
                HeightRequest = inner
            };

            _colorLabel = new Label()
            {
                XAlign        = TextAlignment.Center,
                YAlign        = TextAlignment.Center,
                WidthRequest  = inner,
                HeightRequest = inner,
                Text          = "Tap Me!",
                TextColor     = Color.White
            };

            layout.Children.Add(_loadingIndicator);
            layout.Children.Add(_colorLabel);

            _singleTap         = new TapGestureRecognizer();
            _singleTap.Tapped += SingleTap;

            //doubletap only works on iOs for now
            _doubleTap = new TapGestureRecognizer()
            {
                NumberOfTapsRequired = 2
            };
            _doubleTap.Tapped += (sender, e) => {
                Device.BeginInvokeOnMainThread(() => _colorLabel.Text = string.IsNullOrEmpty(_colorLabel.Text) ? _colorData.Title : string.Empty);
            };

            this.GestureRecognizers.Add(_doubleTap);
            this.GestureRecognizers.Add(_singleTap);


            this.Content = new Frame()
            {
                Content         = layout,
                HasShadow       = true,
                BackgroundColor = Color.Navy,
                OutlineColor    = Color.Gray,
                Padding         = new Thickness(1)
            };
        }
예제 #2
0
 public void ChangeColor()
 {
     Device.BeginInvokeOnMainThread(async() => {
         _loadingIndicator.IsVisible = true;
         _colorData                   = await ColourLoverClient.GetNewRandomColorAsync();
         _colorLabel.Text             = string.IsNullOrEmpty(_colorLabel.Text) ? string.Empty : _colorData.Title;
         this.Content.BackgroundColor = Color.FromHex(_colorData.Hex);
         _loadingIndicator.IsVisible  = false;
     });
 }