//Displays last event for user
        private void DisplayLastEvent()
        {
            if (!matchData.Any())
            {
                Undo_Button.IsEnabled = false;

                LastEventType_TextBlock.Visibility  = Visibility.Visible;
                LastEventStage_TextBlock.Visibility = Visibility.Collapsed;
                LastEventTime_TextBlock.Visibility  = Visibility.Collapsed;
                LastEventType_TextBlock.Text        = "Match Started";
                LastEventStage_TextBlock.Text       = string.Empty;
                LastEventTime_TextBlock.Text        = string.Empty;

                return;
            }

            Undo_Button.IsEnabled = true;

            LastEventType_TextBlock.Visibility  = Visibility.Visible;
            LastEventStage_TextBlock.Visibility = Visibility.Visible;
            LastEventType_TextBlock.Text        = matchData[0].Type;
            LastEventStage_TextBlock.Text       = matchData[0].Stage.ToString();

            ITimedMatchDataElement timedMatchDataElement = matchData[0] as ITimedMatchDataElement;

            if (timedMatchDataElement == null)
            {
                LastEventTime_TextBlock.Visibility = Visibility.Collapsed;
                LastEventTime_TextBlock.Text       = string.Empty;
            }
            else
            {
                LastEventTime_TextBlock.Visibility = Visibility.Visible;
                LastEventTime_TextBlock.Text       = string.Format(@"{0:m\:ss}", SecondsRemaining(timedMatchDataElement.Time));
            }

            int repeatCount = 0;

            for (int i = 0; matchData[i].GetType() == matchData[0].GetType(); i++)
            {
                repeatCount = i;
                if (matchData.Count <= i + 1)
                {
                    break;
                }
            }
            if (repeatCount > 0)
            {
                LastEventRepeatCount_TextBlock.Visibility = Visibility.Visible;
                LastEventRepeatCount_TextBlock.Text       = string.Format("({0})", repeatCount + 1);
            }
            else
            {
                LastEventRepeatCount_TextBlock.Visibility = Visibility.Collapsed;
                LastEventRepeatCount_TextBlock.Text       = string.Empty;
            }
        }
        private async void SaveData_Button_Click(object sender, RoutedEventArgs e)
        {
            App.MatchInfo_Cache.PostmatchNotes = !PostmatchNotes_TextBox.Text.Any() ? null : new MatchInfoElement <String>()
            {
                Value = PostmatchNotes_TextBox.Text
            };

            //Copy data to single object
            DateTime now = DateTime.Now;

            string[] alliance         = App.MatchInfo_Cache.Alliance.Value.Split(' ');
            String   allianceColor    = alliance[0];
            Byte     alliancePosition = Byte.Parse(alliance[1]);

            Data data = new Data()
            {
                DateTime         = now,
                RecorderID       = App.MatchInfo_Cache.RecorderID.Value,
                EventName        = App.MatchInfo_Cache.Event.Value,
                AllianceColor    = allianceColor,
                AlliancePosition = alliancePosition,
                TeamNumber       = App.MatchInfo_Cache.TeamNumber.Value,
                MatchNumber      = App.MatchInfo_Cache.MatchNumber.Value,
                PrematchNotes    = App.MatchInfo_Cache.PrematchNotes?.Value,
                PostmatchNotes   = App.MatchInfo_Cache.PostmatchNotes?.Value
            };

            //Loop throught match events
            while (matchData.Any())
            {
                if (matchData[0].GetType() == typeof(CrossBaseline))
                {
                    data.AutonomousCrossBaseline = true;
                }
                else if (matchData[0].GetType() == typeof(CubeFromFloor))
                {
                    if (matchData[0].Stage == Stage.Autonomous)
                    {
                        data.AutonomousCubeFromFloorCount++;
                    }
                    else
                    {
                        data.TeleopCubeFromFloorCount++;
                    }
                }

                matchData.RemoveAt(0);
            }

            //Convert data object to json string
            string data_json = JsonConvert.SerializeObject(data, Formatting.Indented);

            //Non-roaming scouting data folder
            if (!Directory.Exists(App.ScoutingDataLocation))
            {
                Directory.CreateDirectory(App.ScoutingDataLocation);
            }
            string dataFile = Path.Combine(App.ScoutingDataLocation, string.Format("Match{0}-{1}{2}-{3:yyyy-MM-ddTHH-mm-ss-fffffff}.json", data.MatchNumber, data.AllianceColor, data.AlliancePosition, data.DateTime));

            using (StreamWriter writer = new StreamWriter(dataFile)) {
                await writer.WriteAsync(data_json);
            }

            App.MatchInfo_Cache.MatchNumber.Value++;
            App.MatchInfo_Cache.TeamNumber    = null;
            App.MatchInfo_Cache.PrematchNotes = null;

            NavigationService.Navigate(new MatchInfo_Page());
        }