-
Notifications
You must be signed in to change notification settings - Fork 7
Home
Welcome to the wpf.lazycombobox wiki!
To use this control, add the assembly to your project. In VisualStudio open the designer of your respective XAML file and either drag the control from the panel or add the <u:LazyComboBox DisplayMemberPath="CompanyName" LookupAction="{Binding Filter}" SelectedItem="{Binding SelectedEntry}" />
tag in XAML.
There are multiple modes of operation:
You can use the following XAML code to lazy-load a list of objects: <u:LazyComboBox DisplayMemberPath="CompanyName" LookupAction="{Binding Filter}" SelectedItem="{Binding SelectedEntry}" />
. Note that you DON'T have to supply a ItemsSource which minimizes the amount of data to have to eager-load.
DisplayMemberPath
defines the property to display when the control does not have input-focus, and also defines the property to search for, when the user starts to type text into the LazyComboBox.
LookupAction
defines the method invoked by the LazyComboBox to populate the list, when the user starts typing or opens the dropdown. See below for details.
SelectedItem
is bound 2-way and initially gets the currently selected value. The LazyComboBox will use the DisplayMemberPath (or a fallback to DisplayColumnAttribute of the value's Type, then ToString()) to extract the display-text to show.
The XAML code <u:LazyComboBox Text="{Binding TextEntry}" ItemsSource="{Binding TextEntries}" />
binds to a static list of texts, and supplies the entered or chosen text via the Text
property. Alternatively to supplying a static ItemsSource
, you could also use LookupAction
, as above.
The XAML code <u:LazyComboBox DisplayMemberPath="DisplayName" SelectedValuePath="Id" IsEditable="False" SelectedValue="{Binding Gender}" ItemsSource="{Binding GenderTypes}" />
for example will take a specific property of the currently selected item (SelectedItem
) and extract it's value (based on SelectedValuePath
) to SelectedValue
. If you assign SelectedValue
a new value, LazyComboBox will try to locate the corresponding list-entry by checking the SelectedValuePath
of each entry, until it's value matches the SelectedValue
.
Specify a property in your ViewModel: public Action<LookupContext> Filter { get; }
. Create the delegate method and assign it to filter in your ViewModel's ctor.
The delegate has the following signature void OnFilter(LookupContext ctx)
. The passed LookupContext holds the information required for your implementation to fetch the corresponding records. Please note that this action usually will NOT run in the UI thread! You should also check for the supplied CancellationToken to abort any running lookup. Cancellation will be invoked, when the user refines his search-phrase.
How can I block the user from being able to enter text?
Set the
IsEditable
property toFalse
SelectedItem
is reset to NULL, when the dropdown is opened
this occurs if the LazyComboBox cannot find (by using .Equals()) a match within the ItemsSource (either assigned directly or supplied by the LookupAction). Make sure you have overwritten .Equals() in your class.