Beispiel #1
0
        /// Binds the Label to the game score model so later another control/window can update the
        /// state counter on the game score view
        /// parameter sender: Label from the game score view </param>
        private void StateLabel_OnLoaded(object sender, RoutedEventArgs e)
        {
            if (sender is Label statsLabel)
            {
                string currentTag = statsLabel.Tag as string;

                DependencyProperty dependencyProperty = Label.ContentProperty;
                GameScoreModel     source             = this.GameScoreData;

                if (currentTag == "DrawsBind")
                {
                    source.DrawsTxt = statsLabel.Content as string;
                    source.Draws    = INTIT_STAT_VALUE;
                    bindIt(nameof(source.DrawsBind));
                }
                else if (currentTag == "Player1WinsBind")
                {
                    this.GameScoreData.Player1WinsTxt = statsLabel.Content as string;
                    this.GameScoreData.Player1Wins    = INTIT_STAT_VALUE;
                    bindIt(nameof(this.GameScoreData.Player1WinsBind));
                }
                else if (currentTag == "Player2WinsBind")
                {
                    this.GameScoreData.Player2WinsTxt = statsLabel.Content as string;
                    this.GameScoreData.Player2Wins    = INTIT_STAT_VALUE;
                    bindIt(nameof(this.GameScoreData.Player2WinsBind));
                }

                void bindIt(string path)
                => statsLabel.SetBinding(dependencyProperty, new Binding(path)
                {
                    Source = source
                });
            }
        }
Beispiel #2
0
        public GameScore()
        {
            InitializeComponent();

            this.GameScoreData = new GameScoreModel();
        }