Ejemplo n.º 1
0
        /// <summary>
        /// Opens a file dialog for the user to navigate to their saved game file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Open_Click(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)
        {
            bool?result = fileOpener.ShowDialog();

            if (result != null)
            {
                bool bResult = (bool)result;

                if (bResult)
                {
                    filePath = fileOpener.FileName;

                    using (FileStream dataFileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                    {
                        // deserialize and re-assign objects here
                        penteController = (PenteController)formatter.Deserialize(dataFileStream);
                        LoadSavedGame(penteController.GetGameBoard());

                        Binding binding1 = new Binding("CurrentPlayerName")
                        {
                            Source       = penteController,
                            StringFormat = $"Current Player: {0}"
                        };
                        lblCurrentPlayer.SetBinding(ContentProperty, binding1);
                    }
                }
            }
        }