未验证 提交 dbccf947 编写于 作者: J Jérôme Laban 提交者: GitHub

Merge pull request #12615 from TopProgrammer77/bug-12583-AutoSuggestBox-ItemContainerStyle

fix(AutoSuggestBox): fix the AutoSuggestBox not working when using custom ItemContainerStyle
......@@ -230,6 +230,46 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
SUT.Focus(FocusState.Programmatic);
await WindowHelper.WaitForIdle();
}
[TestMethod]
public async Task When_Using_Custom_ItemContainerStyle()
{
AutoSuggestBox SUT = new AutoSuggestBox
{
ItemContainerStyle = new Style(typeof(ListViewItem))
{
Setters =
{
new Setter(Control.HorizontalAlignmentProperty, HorizontalAlignment.Stretch),
},
}
};
string[] suggestions = { "a1", "a2", "b1", "b2" };
SUT.TextChanged += (s, e) =>
{
if (e.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
{
s.ItemsSource = suggestions.Where(i => i.StartsWith(s.Text));
}
};
WindowHelper.WindowContent = SUT;
await WindowHelper.WaitForIdle();
var textBox = (TextBox)SUT.GetTemplateChild("TextBox");
var listView = (ListView)SUT.GetTemplateChild("SuggestionsList");
SUT.Focus(FocusState.Programmatic);
textBox.ProcessTextInput("a");
await WindowHelper.WaitForIdle();
await WindowHelper.WaitFor(() => SUT.IsSuggestionListOpen);
Assert.AreEqual(2, listView.Items.Count);
Assert.AreEqual("a1", listView.Items[0].ToString());
Assert.AreEqual("a2", listView.Items[1].ToString());
#if __WASM__
//ItemsPanelRoot.Children works only on wasm
Assert.AreEqual(2, listView.ItemsPanelRoot.Children.Count);
Assert.AreEqual("a1", (listView.ItemsPanelRoot.Children[0] as ContentControl).Content.ToString());
Assert.AreEqual("a2", (listView.ItemsPanelRoot.Children[1] as ContentControl).Content.ToString());
#endif
}
#endif
[TestMethod]
......
......@@ -106,6 +106,11 @@ namespace Windows.UI.Xaml.Controls
UpdateSuggestionList();
}
protected override DependencyObject GetContainerForItemOverride()
{
return new ListViewItem() { IsGeneratedContainer = true };
}
internal override void OnItemsSourceGroupsChanged(object sender, NotifyCollectionChangedEventArgs args)
{
base.OnItemsSourceGroupsChanged(sender, args);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册