Example #1
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            this.OneWayBind(ViewModel, vm => vm.EndGame, v => v.EndScreen.IsVisible);
            this.WhenAnyValue(x => x.ViewModel.EndGame).Subscribe(x =>
            {
                Board.IsVisible = !x;
            });


            this.WhenAny(x => x.Board.Width, x => x.Value)
            .Subscribe(x =>
            {
                if (!init && x > 0)
                {
                    Board.HeightRequest = x;
                    Board.WidthRequest  = x;

                    EndScreen.WidthRequest  = x;
                    EndScreen.HeightRequest = x;
                }
            });

            this.WhenAny(x => x.ViewModel.Squares, x => x.Value)
            .Subscribe(x => BindableLayout.SetItemsSource(Board, x));

            this.WhenAny(x => x.ViewModel.BestScore, x => x.Value)
            .Subscribe(x => bestScoreLabel.Text = "BEST SCORE: " + x);

            this.WhenAny(x => x.ViewModel.board.Score, x => x.Value)
            .Subscribe(x =>
            {
                pointsLabel.Text = "CURRENT SCORE: " + x;
            });

            this.BindCommand(ViewModel, x => x.GoToMenu, v => v.backMenuBtn);
            this.BindCommand(ViewModel, x => x.ReplayLevel, v => v.replayBtn);

            if (!init)
            {
                PanGesture.Events().PanUpdated.InvokeCommand(ViewModel.SwitchMove);
            }

            init = true;
        }