private async void SaveButton_Click(object sender, RoutedEventArgs e) { int count = SourceChannelListView.SelectedItems.Count; var channelList = new List <Channel>(); foreach (var item in SourceChannelListView.SelectedItems) { channelList.Add(item as Channel); } if (channelList == null || channelList.Count == 0) { new PopupToast(AppTools.GetReswLanguage("Tip_NoChannelSelect"), AppTools.GetThemeSolidColorBrush(ColorType.ErrorColor)).ShowPopup(); return; } string icon = IconTextBlock.Text; string name = PageNameTextBox.Text; if (string.IsNullOrEmpty(icon) || string.IsNullOrEmpty(name)) { new PopupToast(AppTools.GetReswLanguage("Tip_FieldEmpty"), AppTools.GetThemeSolidColorBrush(ColorType.ErrorColor)).ShowPopup(); return; } if (FilterCollection.Count > 0) { foreach (var item in FilterCollection) { if (item.Rule.Type == FilterRuleType.Filter || item.Rule.Type == FilterRuleType.FilterOut) { try { var regex = new Regex(item.Content); } catch (Exception) { new PopupToast(AppTools.GetReswLanguage("Tip_InputRegexError"), AppTools.GetThemeSolidColorBrush(ColorType.ErrorColor)).ShowPopup(); return; } } else { var numberRegex = new Regex(@"\d+"); if (!numberRegex.IsMatch(item.Content)) { new PopupToast(AppTools.GetReswLanguage("Tip_InputNumberError"), AppTools.GetThemeSolidColorBrush(ColorType.ErrorColor)).ShowPopup(); return; } } } } if (_sourcePage == null || string.IsNullOrEmpty(_sourcePage.Id)) { _sourcePage = new CustomPage(); _sourcePage.Id = Guid.NewGuid().ToString("N"); _sourcePage.Name = name; _sourcePage.Icon = icon; _sourcePage.Rules = FilterCollection.ToList(); _sourcePage.Channels = channelList; MainPage.Current.CustomPages.Add(_sourcePage); MainPage.Current.PageListView.SelectedItem = _sourcePage; MainPage.Current.MainFrame.Navigate(typeof(CustomPageDetailPage), _sourcePage); await IOTools.AddPage(_sourcePage); } else { _sourcePage.Name = name; _sourcePage.Icon = icon; _sourcePage.Rules = FilterCollection.ToList(); _sourcePage.Channels = channelList; foreach (var item in MainPage.Current.CustomPages) { if (item.Id == _sourcePage.Id) { item.Name = _sourcePage.Name; item.Icon = _sourcePage.Icon; item.Rules = FilterCollection.ToList(); item.Channels = channelList; MainPage.Current.PageListView.SelectedItem = _sourcePage; MainPage.Current.MainFrame.Navigate(typeof(CustomPageDetailPage), _sourcePage); break; } } await IOTools.UpdatePage(_sourcePage); } }