private void TokenItemCreating(object sender, TokenItemAddingEventArgs e) { // Take the user's text and convert it to our data type (if we have a matching one). e.Item = _categories.FirstOrDefault((item) => item.categoryName.Contains(e.TokenText, StringComparison.CurrentCultureIgnoreCase)); if (e.Item == null) { e.Cancel = true; } }
private void TagTokens_TokenItemAdding(TokenizingTextBox sender, TokenItemAddingEventArgs args) { // If the tag exists, use it. Otherwise cancel the event. if (App.Context.Tags.Local.Any(tag => tag.Name.Equals(args.TokenText, StringComparison.InvariantCultureIgnoreCase))) { Tag tag = App.Context.Tags.Local.First(tag => tag.Name.Equals(args.TokenText, StringComparison.InvariantCultureIgnoreCase)); args.Item = tag; args.Cancel = false; return; } args.Cancel = true; }
private void TokenItemCreating(object sender, TokenItemAddingEventArgs e) { // Take the user's text and convert it to our data type (if we have a matching one). e.Item = _samples.FirstOrDefault((item) => item.Text.Contains(e.TokenText, System.StringComparison.CurrentCultureIgnoreCase)); // Otherwise, create a new version of our data type if (e.Item == null) { e.Item = new SampleDataType() { Text = e.TokenText, Icon = Symbol.OutlineStar }; } }
private void EmailTokenItemAdding(TokenizingTextBox sender, TokenItemAddingEventArgs args) { // Search our list for a matching person foreach (var person in _emailSamples) { if (args.TokenText.Contains(person.EmailAddress) || args.TokenText.Contains(person.DisplayName, StringComparison.CurrentCultureIgnoreCase)) { args.Item = person; return; } } // Otherwise don't create a token. args.Cancel = true; }
private async void TokenBox_TokenItemTokenItemAdding(TokenizingTextBox sender, TokenItemAddingEventArgs args) { using (args.GetDeferral()) { // Try and convert typed text to people var graph = ProviderManager.Instance.GlobalProvider.Graph; if (graph != null) { args.Item = (await graph.FindPersonAsync(args.TokenText)).CurrentPage.FirstOrDefault(); } // If we didn't find anyone, then don't add anyone. if (args.Item == null) { args.Cancel = true; // TODO: We should raise a 'person not found' type event or automatically display some feedback? } } }