diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TabView/TabViewPage.xaml.cs b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TabView/TabViewPage.xaml.cs index 7f0c212e516..643fdcfb38c 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TabView/TabViewPage.xaml.cs +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TabView/TabViewPage.xaml.cs @@ -69,5 +69,5 @@ private void Tabs_TabDraggedOutside(object sender, TabDraggedOutsideEventArgs e) TabViewNotification.Show("Tore Tab '" + str + "' Outside of TabView.", 2000); } #pragma warning restore CS0618 // Type or member is obsolete - } + } } diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxXaml.bind index 287385ad55a..e9aca6ebd2a 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxXaml.bind +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxXaml.bind @@ -16,7 +16,7 @@ diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.cs index 5f0cb22f0df..1c1731e5105 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.cs @@ -8,6 +8,8 @@ using System.Threading.Tasks; using Microsoft.Toolkit.Uwp.Deferred; using Microsoft.Toolkit.Uwp.Extensions; +using Microsoft.Toolkit.Uwp.UI.Extensions; +using Microsoft.Toolkit.Uwp.UI.Helpers; using Windows.System; using Windows.UI.Core; using Windows.UI.Xaml; @@ -435,6 +437,8 @@ internal async Task AddTokenAsync(object data, bool? atEnd = null) last?._autoSuggestTextBox.Focus(FocusState.Keyboard); TokenItemAdded?.Invoke(this, data); + + GuardAgainstPlaceholderTextLayoutIssue(); } private void UpdateCurrentTextEdit(PretokenStringContainer edit) @@ -475,7 +479,34 @@ private async Task RemoveTokenAsync(TokenizingTextBoxItem item, object dat TokenItemRemoved?.Invoke(this, data); + GuardAgainstPlaceholderTextLayoutIssue(); + return true; } + + private void GuardAgainstPlaceholderTextLayoutIssue() + { + // If the *PlaceholderText is visible* on the last AutoSuggestBox, it can incorrectly layout itself + // when the *ASB has focus*. We think this is an optimization in the platform, but haven't been able to + // isolate a straight-reproduction of this issue outside of this control (though we have eliminated + // most Toolkit influences like ASB/TextBox Style, the InterspersedObservableCollection, etc...). + // The only Toolkit component involved here should be WrapPanel (which is a straight-forward Panel). + // We also know the ASB itself is adjusting it's size correctly, it's the inner component. + // + // To combat this issue: + // We toggle the visibility of the Placeholder ContentControl in order to force it's layout to update properly + var placeholder = ContainerFromItem(_lastTextEdit).FindDescendantByName("PlaceholderTextContentPresenter"); + + if (placeholder?.Visibility == Visibility.Visible) + { + placeholder.Visibility = Visibility.Collapsed; + + // After we ensure we've hid the control, make it visible again (this is inperceptable to the user). + _ = CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => + { + placeholder.Visibility = Visibility.Visible; + }); + } + } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.xaml b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.xaml index ab583789a1a..2bad43277c0 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.xaml +++ b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.xaml @@ -12,7 +12,7 @@ 0,0,6,0 2 2 - + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBoxItem.AutoSuggestBox.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBoxItem.AutoSuggestBox.cs index 827455c37d2..5249da78907 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBoxItem.AutoSuggestBox.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBoxItem.AutoSuggestBox.cs @@ -101,6 +101,15 @@ private void OnApplyTemplateAutoSuggestBox(AutoSuggestBox auto) // Setup a binding to the QueryIcon of the Parent if we're the last box. if (Content is PretokenStringContainer str && str.IsLast) { + // Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/2568 + if (Owner.QueryIcon is FontIconSource fis && + fis.ReadLocalValue(FontIconSource.FontSizeProperty) == DependencyProperty.UnsetValue) + { + // This can be expensive, could we optimize? + // Also, this is changing the FontSize on the IconSource (which could be shared?) + fis.FontSize = Owner.TryFindResource("TokenizingTextBoxIconFontSize") as double? ?? 16; + } + var iconBinding = new Binding() { Source = Owner, diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBoxItem.AutoSuggestBox.xaml b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBoxItem.AutoSuggestBox.xaml index 95651105749..61506d7540e 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBoxItem.AutoSuggestBox.xaml +++ b/Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBoxItem.AutoSuggestBox.xaml @@ -4,7 +4,8 @@ 10,3,6,6 - + 16 +