.net 个性化自动完成文本框Windows 8 Metro应用程序

.net 个性化自动完成文本框Windows 8 Metro应用程序,.net,wpf,vb.net,xaml,windows-store-apps,.net,Wpf,Vb.net,Xaml,Windows Store Apps,我的应用程序中有一个字段,用于包含交易编号。此文本框字段必须根据用户输入提供交易编号的建议 例如,假设我有交易编号“12345”、“12346”和“53213” 如果用户在文本框中键入“123”,我希望文本框显示“12345”和“12346”。如果用户点击“12346”,texbox的值将变为“12346” windows 8 metro应用程序中似乎不再存在autocompletebox,并且IsTextPredictionEnabled属性仅适用于常用词 我的问题如下:我似乎找不到任何类似于

我的应用程序中有一个字段,用于包含交易编号。此文本框字段必须根据用户输入提供交易编号的建议

例如,假设我有交易编号“12345”、“12346”和“53213”

如果用户在文本框中键入“123”,我希望文本框显示“12345”和“12346”。如果用户点击“12346”,texbox的值将变为“12346”

windows 8 metro应用程序中似乎不再存在autocompletebox,并且IsTextPredictionEnabled属性仅适用于常用词

我的问题如下:我似乎找不到任何类似于listbox的ItemSource属性的东西


如何给文本框赋值,使其知道使用什么自动完成?

我改变了主意,没有使用自动完成文本框,而是使用链接到列表框的常规文本框。如果找到项,列表框将呈现为可见,如果没有,则折叠

此代码将获取来自web服务的字符串值(值可能来自其他任何地方),并通过验证过程查看它们是否可以显示在自动完成列表框中

这是我的XAML代码:

<StackPanel Orientation="Vertical" Grid.Column="1">
    <TextBox x:Name="txtNumeroBon"
             Width="{Binding ElementName=PanelBon, Path=ActualWidth}"
             Style="{StaticResource TextBoxStyles}"
             Margin="8,0,8,0"
             TextChanged="txtNumeroBon_TextChanged"/>

    <ListBox x:Name="lstNumeroBon"
             Visibility="Collapsed"
             Margin="8,0,8,0"
             Height="150"
             SelectionChanged="lstNumeroBon_SelectionChanged"/>
</StackPanel>
这是我的listboxSelectionChanged方法:

    Private Async Function txtNumeroBon_TextChanged(sender As Object, e As TextChangedEventArgs) As Task
        Dim lstSearch As List(Of String) = New List(Of String)
        lstNumeroBon.Visibility = Windows.UI.Xaml.Visibility.Collapsed

        //Only start searching if there are more than 3 characters
        If txtNumeroBon.Text.Length > 2 Then
            //Get the values for the autocomplete into a list
            Dim lstResult = (From p In Await DataService.InstPatronController.GetInstPatron).ToList()
            For i = 0 To lstResult.Count - 1
                // If the item being searched is bigger than the textbox value
                If lstResult(i).Type.ToString.Length > txtNumeroBon.Text.Length Then
                    //Compare items in lstResult to the textbox value and add if they fit
                    If lstResult(i).Type.Substring(0, txtNumeroBon.Text.Length).ToLower() = txtNumeroBon.Text.ToLower() Then
                        lstSearch.Add(lstResult(i).Type.ToString())
                    End If
                End If
            Next
            //If 1 or more items fit the search
            If lstSearch.Count > 0 Then
                lstNumeroBon.ItemsSource = lstSearch
                lstNumeroBon.Visibility = Windows.UI.Xaml.Visibility.Visible
            End If
        End If
    End Function
Private Sub lstNumeroBon_SelectionChanged(sender As Object, e As SelectionChangedEventArgs)
    // Verify index to avoid Argument out of range exception
    If lstNumeroBon.SelectedIndex < lstNumeroBon.Items.Count - 1 And lstNumeroBon.SelectedIndex > -1 Then
        txtNumeroBon.Text = lstNumeroBon.Items(lstNumeroBon.SelectedIndex).ToString()
        lstNumeroBon.Visibility = Windows.UI.Xaml.Visibility.Collapsed
    End If
End Sub
Private Sub-lstNumeroBon\u SelectionChanged(发送方作为对象,e作为selectionchangedventargs)
//验证索引以避免参数超出范围异常
如果lstNumeroBon.SelectedIndex-1,则
txtNumeroBon.Text=lstNumeroBon.Items(lstNumeroBon.SelectedIndex.ToString())
lstNumeroBon.Visibility=Windows.UI.Xaml.Visibility.Collapsed
如果结束
端接头

还可以实现
GotFocus
LostFocus
方法来显示和隐藏列表框

如果您键入一个单词的一部分,例如
softw
,只需将IsTextPredictionEnabled设置为True,它似乎什么都不做。然而,我希望向文本框提供我自己的数据,这样像软件这样的文字就不会显示出来。我只会提供数字我的意思是
IsTextPredictionEnabled
是用于建议常用词,而不是用于定制列表…那么,您知道可以使用什么来制作定制列表吗?我想它可以定制,我的错。;