public GameCompletePage()
    {
        InitializeComponent();
        viewModel = this.DataContext as GameCompleteViewModel;
        viewModel.PropertyChanged += HandlePropertyChanged;
 
        Loaded += GameCompletePage_Loaded;
        scanner = new ZXing.Mobile.MobileBarcodeScanner(Deployment.Current.Dispatcher);
    }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
    
            viewModel = new GameCompleteViewModel();
            scanner = new ZXing.Mobile.MobileBarcodeScanner();

            ButtonShare.Layer.CornerRadius = 5;
            scanButton = new UIBarButtonItem("Scan", UIBarButtonItemStyle.Plain, async (sender, args) =>
                {

                    var result = await scanner.Scan(true);

                    if (result == null)
                        return;

                    Console.WriteLine("Scanned Barcode: " + result.Text);
                    viewModel.CheckBanana(result.Text);
                });


            NavigationItem.RightBarButtonItem = scanButton;

            viewModel.PropertyChanged += HandlePropertyChanged;

            manager = new CLLocationManager();
            manager.DidRangeBeacons += (sender2, e) =>
            {
                if (e.Beacons == null)
                    return;

                foreach (var beacon in e.Beacons)
                {
                    if (beacon.Proximity != CLProximity.Immediate)
                    {
                        return;
                    }

                    if (beacon.Accuracy > .1)//close, but not close enough.
            return;

                    viewModel.CheckBanana(beacon.Major.Int32Value, beacon.Minor.Int32Value);
                }
            };



            viewModel.LoadGameCommand.Execute(null);
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            App.CurrentActivity = this;
            ActionBar.SetDisplayHomeAsUpEnabled(true);
            ActionBar.SetHomeButtonEnabled(true);
            viewModel = new GameCompleteViewModel();
            SetContentView(Resource.Layout.game_complete);
            viewModel.PropertyChanged += HandlePropertyChanged;

            mainImage = FindViewById<ImageView>(Resource.Id.main_image);
            progressBar = FindViewById<ProgressBar>(Resource.Id.progressBar);
            beaconManager = new BeaconManager(this);
            scanner = new ZXing.Mobile.MobileBarcodeScanner();

            var shareButton = FindViewById<Button>(Resource.Id.share_success);
            shareButton.Click += (sender, e) =>
            {
                var intent = new Intent(Intent.ActionSend);
                intent.SetType("text/plain");
                intent.PutExtra(Intent.ExtraText, Resources.GetString(Resource.String.success_tweet));
                StartActivity(Intent.CreateChooser(intent, Resources.GetString(Resource.String.share_success)));
            };
      
            beaconManager.Ranging += (sender, e) =>
            {
                if (e.Beacons == null)
                    return;

                foreach (var beacon in e.Beacons)
                {
                    var proximity = Utils.ComputeProximity(beacon);

                    if (proximity != Utils.Proximity.Immediate)
                        continue;

                    var accuracy = Utils.ComputeAccuracy(beacon);
                    if (accuracy > .06)
                        continue;

                    viewModel.CheckBanana(beacon.Major, beacon.Minor);
                }
            };


            viewModel.LoadGameCommand.Execute(null);

        }