Export (0) Print
Expand All
Expand Minimize

AutoCompleteFilterMode Enumeration

Silverlight

Specifies how text in the text box portion of the AutoCompleteBox control is used to filter items specified by the ItemsSource property for display in the drop-down.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.Input (in System.Windows.Controls.Input.dll)

'Declaration
Public Enumeration AutoCompleteFilterMode

Member nameDescription
NoneSpecifies that no filter is used. All items are returned.
StartsWithSpecifies a culture-sensitive, case-insensitive filter where the returned items start with the specified text. The filter uses the String.StartsWith method, specifying StringComparer.CurrentCultureIgnoreCase as the string comparison criteria.
StartsWithCaseSensitiveSpecifies a culture-sensitive, case-sensitive filter where the returned items start with the specified text. The filter uses the String.StartsWith method, specifying StringComparer.CurrentCulture as the string comparison criteria.
StartsWithOrdinalSpecifies an ordinal, case-insensitive filter where the returned items start with the specified text. The filter uses the String.StartsWith method, specifying StringComparer.OrdinalIgnoreCase as the string comparison criteria.
StartsWithOrdinalCaseSensitiveSpecifies an ordinal, case-sensitive filter where the returned items start with the specified text. The filter uses the String.StartsWith method, specifying StringComparer.Ordinal as the string comparison criteria.
ContainsSpecifies a culture-sensitive, case-insensitive filter where the returned items contain the specified text.
ContainsCaseSensitiveSpecifies a culture-sensitive, case-sensitive filter where the returned items contain the specified text.
ContainsOrdinalSpecifies an ordinal, case-insensitive filter where the returned items contain the specified text.
ContainsOrdinalCaseSensitiveSpecifies an ordinal, case-sensitive filter where the returned items contain the specified text.
EqualsSpecifies a culture-sensitive, case-insensitive filter where the returned items equal the specified text. The filter uses the String.Equals method, specifying StringComparer.CurrentCultureIgnoreCase as the search comparison criteria.
EqualsCaseSensitiveSpecifies a culture-sensitive, case-sensitive filter where the returned items equal the specified text. The filter uses the String.Equals method, specifying StringComparer.CurrentCulture as the string comparison criteria.
EqualsOrdinalSpecifies an ordinal, case-insensitive filter where the returned items equal the specified text. The filter uses the String.Equals method, specifying StringComparer.OrdinalIgnoreCase as the string comparison criteria.
EqualsOrdinalCaseSensitiveSpecifies an ordinal, case-sensitive filter where the returned items equal the specified text. The filter uses the String.Equals method, specifying StringComparer.Ordinal as the string comparison criteria.
CustomSpecifies that a custom filter is used. This mode is used when the AutoCompleteBox.TextFilter or AutoCompleteBox.ItemFilter properties are set.

An ordinal filter is a filter that uses the Unicode values of strings when performing comparisons.

Use None when the data source performs its own filtering.

The following example shows how to use the ValueMemberPath and FilterMode properties to populate the drop-down portion of the AutoCompleteBox control.

Run this sample


Imports System.Collections

Partial Public Class MainPage
    Inherits UserControl
    Private MyMusic As New List(Of Recording)()
    Public Sub New()
        InitializeComponent()

        ' Add items to the collection. 
        MyMusic.Add(New Recording("Chris Sells", "Chris Sells Live", _
            New DateTime(2008, 3, 5)))
        MyMusic.Add(New Recording("Chris Sells", "Sells Tells", _
            New DateTime(2004, 4, 6)))
        MyMusic.Add(New Recording("Luka Abrus", "The Road to Redmond", _
            New DateTime(2007, 8, 3)))
        MyMusic.Add(New Recording("Luka Abrus", "Luka", _
            New DateTime(2005, 12, 8)))
        MyMusic.Add(New Recording("Luka Abrus", "Love and Luka ", _
            New DateTime(2005, 11, 8)))
        MyMusic.Add(New Recording("Jim Hance", "The Best of Jim Hance", _
            New DateTime(2007, 2, 6)))

        ' Set the data context for the AutoCompleteBox. 
        myACB.DataContext = MyMusic
    End Sub
End Class

' Simple business object. 
Public Class Recording
    Public Sub New()
    End Sub
    Public Sub New(ByVal artistName As String, ByVal cdName As String, _
                   ByVal release As DateTime)
        Artist = artistName
        Name = cdName
        ReleaseDate = release
    End Sub
    Private _Artist As String
    Public Property Artist() As String
        Get
            Return _Artist
        End Get
        Set(ByVal value As String)
            _Artist = value
        End Set
    End Property
    Private _Name As String
    Public Property Name() As String
        Get
            Return _Name
        End Get
        Set(ByVal value As String)
            _Name = value
        End Set
    End Property
    Private _ReleaseDate As DateTime
    Public Property ReleaseDate() As DateTime
        Get
            Return _ReleaseDate
        End Get
        Set(ByVal value As DateTime)
            _ReleaseDate = value
        End Set
    End Property
End Class



<!-- NOTE: 
  By convention, the sdk prefix indicates a URI-based XAML namespace declaration 
  for Silverlight SDK client libraries. This namespace declaration is valid for 
  Silverlight 4 only. In Silverlight 3, you must use individual XAML namespace 
  declarations for each CLR assembly and namespace combination outside the scope 
  of the default Silverlight XAML namespace. For more information, see the help 
  topic "Prefixes and Mappings for Silverlight Libraries". 
-->
<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    x:Class="ACBValueMemberPath.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:ACBValueMemberPath"
    Width="400" Height="413">
    <StackPanel x:Name="LayoutRoot" Background="White" >
        <StackPanel Orientation="Horizontal">
         <TextBlock Margin="5" Text="Enter a recording name:" TextWrapping="Wrap" />
            <sdk:AutoCompleteBox FilterMode="ContainsOrdinal" VerticalAlignment="Top" Margin="5" Width="170" 
                Height="30" x:Name="myACB" 
                ItemsSource="{Binding}" 
                ValueMemberPath="Name">
                <sdk:AutoCompleteBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                        <TextBlock Text="{Binding Path=Name}"  />
                        <TextBlock Text="{Binding Path=Artist}"  />
                        </StackPanel>
                    </DataTemplate>
                </sdk:AutoCompleteBox.ItemTemplate>
            </sdk:AutoCompleteBox>
        </StackPanel>
      </StackPanel>
</UserControl>


The following example shows how to set the FilterMode to Custom, and then set the ItemFilter property to a custom filter method for the Employee object. The custom filter returns matches from employees' first or last name. This code example requires a reference to the System.Windows.Controls.Input assembly.


Private employees As New List(Of Employee)()
Public Sub New()
    InitializeComponent()
    ' Add some items to the employee list. 
    employees.Add(New Employee("Sells", "Chris", "csells", 1234))
    employees.Add(New Employee("Cabatana", "Reina", "rcaba", 5678))
    employees.Add(New Employee("Sprenger", "Christof", "cspreng", 9123))
    employees.Add(New Employee("Brandel", "Jonas", "jbrandel", 4567))
    employees.Add(New Employee("Bye", "Dennis", "dbye", 8912))
    employees.Add(New Employee("Reid", "Miles", "mreid", 3456))

    ' Set the item source. 
    myACB.ItemsSource = employees


...


       ' Set the ItemFilter property to the search method. 
	 myACB.ItemFilter = AddressOf SearchEmployees


...


End Sub


...


Private Function SearchEmployees(ByVal search As String, ByVal value As Object) As Boolean
    ' Cast the value to an Employee. 
    Dim emp As Employee = TryCast(value, Employee)
    If emp IsNot Nothing Then
        ' Look for a match in the first and last names. 
        If emp.LastName.ToLower().StartsWith(search) Then
            Return True

        ElseIf emp.FirstName.ToLower().StartsWith(search) Then
            Return True
        End If
    End If
    ' If no match, return false. 
    Return False
End Function


...


Public Class Employee
    Private _LastName As String
    Public Property LastName() As String
        Get
            Return _LastName
        End Get
        Set(ByVal value As String)
            _LastName = value
        End Set
    End Property
    Private _FirstName As String
    Public Property FirstName() As String
        Get
            Return _FirstName
        End Get
        Set(ByVal value As String)
            _FirstName = value
        End Set
    End Property
    Private _EmailName As String
    Public Property EmailName() As String
        Get
            Return _EmailName
        End Get
        Set(ByVal value As String)
            _EmailName = value
        End Set
    End Property
    Private _ID As Integer
    Public Property ID() As Integer
        Get
            Return _ID
        End Get
        Set(ByVal value As Integer)
            _ID = value
        End Set
    End Property
    Public Sub New(ByVal empLastName As String, ByVal empFirstName As String, ByVal empEmail As String, ByVal empID As Integer)
        LastName = empLastName
        FirstName = empFirstName
        EmailName = empEmail
        ID = empID
    End Sub
    Public Overloads Overrides Function ToString() As String
        Return ((("Employee: " & FirstName & " ") + LastName + System.Environment.NewLine & "Email: ") + EmailName + System.Environment.NewLine & "ID: ") + ID.ToString()
    End Function
End Class



<StackPanel x:Name="LayoutRoot" Background="LightGray">
     <TextBlock FontWeight="Bold" Text="AutoCompleteBox Custom Filter Example" Margin="5"/>
     <StackPanel  Orientation="Horizontal">
         <TextBlock Text="Employee:" Margin="5" HorizontalAlignment="Left"  VerticalAlignment="Center"/>
         <sdk:AutoCompleteBox Height="75" Width="200" VerticalAlignment="Center" HorizontalAlignment="Right" 
         x:Name="myACB" FilterMode="Custom" ToolTipService.ToolTip="Enter employee name."/>
     </StackPanel>
     </StackPanel>


Silverlight

Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft