WPF Auto Complete Text Box

A simple and useful control for WPF. It supports Binding and MVVM. 

Features:
  • Supports MVVM for auto suggestions
  • Asynchronously load suggestions
  • Supports watermark
  • Supports Icon

Latest release of AutoCompleteTextBox is available at CodePlex or Visual Studio Gallery.

WPF Auto Complete Text Box

Below is a sample code of FilesystemSuggestionProvider.

Public Class FilesystemSuggestionProvider
    Implements ISuggestionProvider

    Public Function GetSuggestions(ByVal filter As String) As System.Collections.IEnumerable Implements ISuggestionProvider.GetSuggestions
        If String.IsNullOrEmpty(filter) Then
            Return Nothing
        End If
        If filter.Length < 3 Then
            Return Nothing
        End If

        If filter(1) <> ":"c Then
            Return Nothing
        End If

        Dim lst As New List(Of IO.FileSystemInfo)
        Dim dirFilter As String = "*"
        Dim dirPath As String = filter
        If Not filter.EndsWith("\") Then
            Dim index As Integer = filter.LastIndexOf("\")
            dirPath = filter.Substring(0, index + 1)
            dirFilter = filter.Substring(index + 1) + "*"
        End If
        Dim dirInfo As IO.DirectoryInfo = New IO.DirectoryInfo(dirPath)
        lst.AddRange(dirInfo.GetFileSystemInfos(dirFilter))
        Return lst
    End Function

End Class

Adding AutoCompleteTextBox in your view:

<wpf:AutoCompleteTextBox VerticalAlignment="Top"
     Height="25"
     Grid.Column="1"
     Text="{Binding Path=FileName, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
     DisplayMember="FullName"
     ItemTemplate="{StaticResource ResourceKey=fsTemplate}"
     Provider="{StaticResource ResourceKey=fsp}" /> 

Kategori

Kategori