<UserControl xmlns:inputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit" x:Class="SearchPopup"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
2) Key Properties and Events
ItemsSource: Set your data here. It can be linked to any IEnumerable object.
IsTextCompletionEnabled: Performs a search on your items and look for the best match. If one is found, the text box is updated with the item's string value.
SelectedItem: Is null if no item is selected (from dropdown).
FilterMode (aka SearchMode in Silverlight 2): Built-in search filter to use.
ItemFilter: 2 inputs (search string and the item as an object). We can define our custom filtering logic based on custom classes.
MinimumPrefixLength: Length of text typed before filtering
DropDownOpening, DropDownOpened, DropDownClosing, DropDownClosed
3) Binding to a list of objects
SearchPopup.ItemsSource = usrInfoList; // usrInfoList is of type List
SearchPopup.ItemFilter += FilterPersons;
bool FilterPersons(string search, object value)
{
User usr = value as User;
if (usr != null)
{
if(usr.Name.Contains(search)) return true;
if(usr.UserID.Contains(search)) return true;
}
return false;
}
This code will bind the AutoCompleteBox to the list of users. When user types in the textbox, the User objects will be displayed (using toString method) if the text that was typed belongs to the name or the userid value of the object.
4) References:
No comments:
Post a Comment