예제 #1
0
 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;
     }
 }
예제 #2
0
        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;
        }
예제 #3
0
        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
                };
            }
        }
예제 #4
0
        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;
        }
예제 #5
0
        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?
                }
            }
        }