コード例 #1
0
        // --------------------------------------------------------------------------
        //
        // CONSTRUCTORS
        //
        // --------------------------------------------------------------------------
        public App()
        {
            // Create the orange image that goes on the main screen of the app
            var orangeImage = new CustomImage {
                Aspect = Aspect.Fill
            };

            orangeImage.Source = "orange_square.png";

            // Create a ContentPage to use as the view of the app.
            var page = new ContentPage {
                Content = new StackLayout {
                    VerticalOptions = LayoutOptions.Center,
                    Children        = { orangeImage }
                }
            };

            // When the image dispatches a tap event (custom event, see CustomImage.cs),
            // then display an alert.
            orangeImage.TapEvent += (object sender, PointEventArgs e) => {
                page.DisplayAlert("Tap!", String.Format("({0}, {1})", e.X, e.Y), "Cancel");
            };

            // Set the main page of the app.
            MainPage = page;
        }
コード例 #2
0
		// ---------------------------------------------------------------------------
		//
		// METHODS
		//
		// ---------------------------------------------------------------------------

		//
		// Use this method to customize the native control as desired
		//
		protected override void OnElementChanged(ElementChangedEventArgs<Image> e) {
			base.OnElementChanged (e);
			if (e.NewElement != null) {
				// Grab the Xamarin.Forms element from the incoming event
				formsElement = e.NewElement as CustomImage;
				// Grab the native implementation of the Xamarin.Forms element from the incoming event
				nativeElement = Control as ImageView;
				// Use this object to handle the touch events coming from the native elemtn
				nativeElement.SetOnTouchListener (this);
				// Create a gesture detector, and use this object to handle its events
				_gestureDetector = new GestureDetector (this);
			}
		}
コード例 #3
0
		// ---------------------------------------------------------------------------
		//
		// METHODS
		//
		// ---------------------------------------------------------------------------

		//
		// Set up the custom renderer. In this case, that means set up the gesture
		// recognizer.
		//
		protected override void OnElementChanged(ElementChangedEventArgs<Image> e) {
			base.OnElementChanged (e);
			if (e.NewElement != null) {
				// Grab the Xamarin.Forms control (not native)
				formsElement = e.NewElement as CustomImage;
				// Grab the native representation of the Xamarin.Forms control
				nativeElement = Control as UIImageView;
				// Set up a tap gesture recognizer on the native control
				nativeElement.UserInteractionEnabled = true;
				UITapGestureRecognizer tgr = new UITapGestureRecognizer (TapHandler);
				nativeElement.AddGestureRecognizer (tgr);
			}
		}
コード例 #4
0
		// --------------------------------------------------------------------------
		//
		// CONSTRUCTORS
		//
		// --------------------------------------------------------------------------
		public App () {
			// Create the orange image that goes on the main screen of the app
			var orangeImage = new CustomImage { Aspect = Aspect.Fill };
			orangeImage.Source = "orange_square.png";

			// Create a ContentPage to use as the view of the app.
			var page = new ContentPage {
				Content = new StackLayout {
					VerticalOptions = LayoutOptions.Center,
					Children = { orangeImage }
				}
			};

			// When the image dispatches a tap event (custom event, see CustomImage.cs),
			// then display an alert.
			orangeImage.TapEvent += (object sender, PointEventArgs e) => {
				page.DisplayAlert("Tap!", String.Format("({0}, {1})", e.X, e.Y), "Cancel");
			};

			// Set the main page of the app.
			MainPage = page;
		}