我安装了 nudget 自动完成工具包,但不幸的是,我发现这个控件没有足够的属性来充当自动完成功能,这很奇怪。它有 ItemsSource 但它不显示在您键入内容时过滤的项目列表。我也在寻找类似 textChanged 的东西,这样我就可以调用我的服务并再次获取结果并绑定 itemsource。
问问题
593 次
3 回答
1
Syncfusion WinRT Studio 中的 TextBoxExt 控件具有足够的功能,可以用作自动完成功能。它有超过 15 种建议模式,包括自定义过滤选项。希望这可以帮助。
于 2013-02-28T03:19:39.310 回答
1
这是我在Group Contacts中使用的实现:
XAML:
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:behaviors="using:MyNamespace.Behaviors"
. .
<TextBox x:Name="Searchbox" PlaceholderText="contact's name" Width="250"
IsTextPredictionEnabled="False"
IsSpellCheckEnabled="False"
VerticalAlignment="Center">
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="KeyUp">
<behaviors:FilterContactAction />
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</TextBox>
代码:
public class FilterContactAction : DependencyObject, IAction
{
string _previousResult = null;
public object Execute(object sender, object parameter)
{
var textbox = sender as TextBox;
var keyEventArgs = parameter as KeyRoutedEventArgs;
var noChanges = textbox.Text == _previousResult;
var deletionOccurred = keyEventArgs.Key == VirtualKey.Back ||
keyEventArgs.Key == VirtualKey.Delete;
if (noChanges || deletionOccurred)
{
return null;
}
var viewModel = ResourceLocator.Instance[typeof(HomeViewModel)] as HomeViewModel;
viewModel.CanSearch = FindMatch(textbox, viewModel.Contacts);
return null;
}
private bool FindMatch(TextBox textbox, ObservableCollection<Contact> contacts)
{
foreach (var contact in contacts)
{
var suggestionDisplayed = DisplaySuggestion(textbox, contact);
if (suggestionDisplayed)
{
return true;
}
}
return false;
}
private bool DisplaySuggestion(TextBox textbox, Windows.ApplicationModel.Contacts.Contact contact)
{
var characterCount = textbox.Text.Count();
var suggestionDisplayed = false;
var isMatch = contact.DisplayName.ToUpper().StartsWith(textbox.Text.ToUpper());
if (isMatch)
{
textbox.Text = contact.DisplayName;
textbox.SelectionStart = characterCount;
textbox.SelectionLength = textbox.Text.Length - textbox.SelectionStart;
_previousResult = textbox.Text;
suggestionDisplayed = true;
}
return suggestionDisplayed;
}
}
于 2014-08-20T18:38:56.457 回答
0
不确定你用的是什么。不能告诉你为什么它也不起作用。但是去年我想要 AutoCompleteTextBox 并最终自己编写了它。
你可以在这里找到它。 https://github.com/hermitdave/HermitDaveWinRTControls
于 2013-02-26T12:31:59.697 回答