diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/SampleEmailDataType.cs b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/SampleEmailDataType.cs
index 0822836189d..3fc2a0eca62 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/SampleEmailDataType.cs
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/SampleEmailDataType.cs
@@ -8,7 +8,7 @@
namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
///
- /// Sample of strongly-typed email address simulated data for .
+ /// Sample of strongly-typed email address simulated data for .
///
public class SampleEmailDataType
{
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxPage.xaml.cs b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxPage.xaml.cs
index 110c6518894..86bbd2121c0 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxPage.xaml.cs
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxPage.xaml.cs
@@ -83,6 +83,7 @@ public sealed partial class TokenizingTextBoxPage : Page, IXamlRenderListener
private TokenizingTextBox _ttbEmail;
private ListView _ttbEmailSuggestions;
private Button _ttbEmailClear;
+ private Button _ttbEmailShowItems;
private AdvancedCollectionView _acv;
private AdvancedCollectionView _acvEmail;
@@ -117,9 +118,6 @@ public void OnXamlRendered(FrameworkElement control)
if (control.FindChildByName("TokenBox") is TokenizingTextBox ttb)
{
_ttb = ttb;
-
- ////_ttb.ItemsSource = new ObservableCollection(); // TODO: This shouldn't be required, we should initialize in control constructor???
-
_ttb.TokenItemAdded += TokenItemAdded;
_ttb.TokenItemRemoving += TokenItemRemoved;
_ttb.TextChanged += TextChanged;
@@ -146,8 +144,7 @@ public void OnXamlRendered(FrameworkElement control)
_ttbEmail = ttbEmail;
_ttbEmail.ItemsSource = _selectedEmails;
-
- // _ttbEmail.ItemClick += EmailTokenItemClick;
+ _ttbEmail.ItemClick += EmailTokenItemClick;
_ttbEmail.TokenItemAdding += EmailTokenItemAdding;
_ttbEmail.TokenItemAdded += EmailTokenItemAdded;
_ttbEmail.TokenItemRemoved += EmailTokenItemRemoved;
@@ -181,9 +178,19 @@ public void OnXamlRendered(FrameworkElement control)
if (control.FindChildByName("ClearButton") is Button btn)
{
_ttbEmailClear = btn;
-
_ttbEmailClear.Click += ClearButtonClick;
}
+
+ if (_ttbEmailShowItems != null)
+ {
+ _ttbEmailShowItems.Click -= ShowButtonClick;
+ }
+
+ if (control.FindChildByName("ShowSelectedEmails") is Button showBtn)
+ {
+ _ttbEmailShowItems = showBtn;
+ _ttbEmailShowItems.Click += ShowButtonClick;
+ }
}
private async void EmailTokenItemClick(object sender, ItemClickEventArgs e)
@@ -316,6 +323,28 @@ private void ClearButtonClick(object sender, RoutedEventArgs e)
_acvEmail.RefreshFilter();
}
+ private async void ShowButtonClick(object sender, RoutedEventArgs e)
+ {
+ // Grab the list of items and identify which ones are free text, which ones are tokens
+ string message = string.Empty;
+
+ foreach (var item in _ttbEmail.Items)
+ {
+ if (!string.IsNullOrEmpty(message))
+ {
+ message += "\r\n";
+ }
+
+ message += item is ITokenStringContainer ? "Unrslvd: " : "Token : ";
+ var textVal = item.ToString();
+
+ message += string.IsNullOrEmpty(textVal) ? "" : textVal;
+ }
+
+ MessageDialog md = new MessageDialog(message, "Item List with type");
+ await md.ShowAsync();
+ }
+
// Move to Email Suggest ListView list when we keydown from the TTB
private void EmailPreviewKeyDown(object sender, KeyRoutedEventArgs e)
{
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxXaml.bind
index fd6626519d3..54ccba3b621 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxXaml.bind
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxXaml.bind
@@ -1,8 +1,9 @@
@@ -15,7 +16,7 @@
@@ -78,7 +79,10 @@
-
+
+
+
+
diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/ITokenStringContainer.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/ITokenStringContainer.cs
new file mode 100644
index 00000000000..b665fc478cd
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/ITokenStringContainer.cs
@@ -0,0 +1,17 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace Microsoft.Toolkit.Uwp.UI.Controls
+{
+ ///
+ /// Provides access to unresolved token string values within the tokenizing text box control
+ ///
+ public interface ITokenStringContainer
+ {
+ ///
+ /// Gets or sets the string text for this unresolved token
+ ///
+ string Text { get; set; }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/PretokenStringContainer.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/PretokenStringContainer.cs
index 7c0ef3bf970..eacd5a2a772 100644
--- a/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/PretokenStringContainer.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/PretokenStringContainer.cs
@@ -6,7 +6,7 @@
namespace Microsoft.Toolkit.Uwp.UI.Controls
{
- internal class PretokenStringContainer : DependencyObject
+ internal class PretokenStringContainer : DependencyObject, ITokenStringContainer
{
public string Text
{
@@ -18,13 +18,25 @@ public string Text
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register(nameof(Text), typeof(string), typeof(PretokenStringContainer), new PropertyMetadata(string.Empty));
- public PretokenStringContainer()
+ public bool IsLast { get; private set; }
+
+ public PretokenStringContainer(bool isLast = false)
{
+ IsLast = isLast;
}
public PretokenStringContainer(string text)
{
Text = text;
}
+
+ ///
+ /// Override and provide the content of the container on ToString() so the calling app can access the token string
+ ///
+ /// The content of the string token
+ public override string ToString()
+ {
+ return Text;
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.Properties.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.Properties.cs
index 48ca960c60b..6a738b4a5a4 100644
--- a/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.Properties.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.Properties.cs
@@ -91,7 +91,7 @@ public partial class TokenizingTextBox : ListViewBase
///
public static readonly DependencyProperty QueryIconProperty = DependencyProperty.Register(
nameof(QueryIcon),
- typeof(IconElement),
+ typeof(IconSource),
typeof(TokenizingTextBox),
new PropertyMetadata(null));
@@ -232,9 +232,9 @@ public string PlaceholderText
///
/// Gets or sets the icon to display in the AutoSuggestBox template part.
///
- public IconElement QueryIcon
+ public IconSource QueryIcon
{
- get => (IconElement)GetValue(QueryIconProperty);
+ get => (IconSource)GetValue(QueryIconProperty);
set => SetValue(QueryIconProperty, value);
}
diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.Selection.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.Selection.cs
index 31c98e025ff..37366371724 100644
--- a/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.Selection.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.Selection.cs
@@ -69,6 +69,18 @@ private bool MoveFocusAndSelection(MoveDirection direction)
if (index != previousIndex)
{
var newItem = ContainerFromIndex(index) as TokenizingTextBoxItem;
+
+ // Check for the new item being a text control.
+ // this must happen before focus is set to avoid seeing the caret
+ // jump in come cases
+ if (Items[index] is PretokenStringContainer && !IsShiftPressed)
+ {
+ newItem._autoSuggestTextBox.SelectionLength = 0;
+ newItem._autoSuggestTextBox.SelectionStart = direction == MoveDirection.Next
+ ? 0
+ : newItem._autoSuggestTextBox.Text.Length;
+ }
+
newItem.Focus(FocusState.Keyboard);
// if no control keys are selected then the selection also becomes just this item
diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.cs
index d1846d24e5a..014dc85aa89 100644
--- a/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.cs
@@ -57,7 +57,7 @@ public TokenizingTextBox()
{
// Setup our base state of our collection
_innerItemsSource = new InterspersedObservableCollection(new ObservableCollection