public void AddBuzzWordAndSave(ListView listView, string buzzWord) { const int buzzWordsLimit = 20; JsonArray buzzWordsCollection = roamingJsonObject.GetOrCreateNamedArray(BuzzWordsKey); IJsonValue selectedValue; if (buzzWordsCollection.ContainsStringValue(buzzWord, out selectedValue)) { // We already have this buzz word. Debug.WriteLine("Buzz word repeated: {0}", buzzWord); return; } if (buzzWordsCollection.Count >= buzzWordsLimit) { MessageDialog dialog = new MessageDialog( String.Format("Only {0} buzz words allowed.", buzzWordsLimit), "Oops."); // Weird, we do not await nor keep a reference to the dialog. var showOperation = dialog.ShowAsync(); return; } buzzWordsCollection.Add(JsonValue.CreateStringValue(buzzWord)); listView.Items.Add(buzzWord); SettingsManager.SaveRoaming(); }
public void DeleteBuzzWordAndSave(ListView listView, string buzzWord) { JsonArray buzzWordsCollection = roamingJsonObject.GetOrCreateNamedArray(BuzzWordsKey); IJsonValue selectedValue; if (buzzWordsCollection.ContainsStringValue(buzzWord, out selectedValue)) { buzzWordsCollection.Remove(selectedValue); SettingsManager.SaveRoaming(); } listView.Items.Remove(buzzWord); }