wpf combobox event for 'item not found' -



wpf combobox event for 'item not found' -

can know if text not compatible no iten in list

<combobox iseditable="true" itemsource="..."/>

there event or property determine if no item found textsearch

you check selecteditem property on combobox , if null while changing, means there no match in list. here have little demo how work.

xaml part:

<window x:class="wpfapplication1.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" height="350" width="525"> <grid> <combobox itemssource="{binding itemssource, updatesourcetrigger=propertychanged}" iseditable="true" text="{binding typedtext, updatesourcetrigger=propertychanged}" height="36" verticalalignment="top"/> </grid>

xaml.cs:

/// <summary> /// interaction logic mainwindow.xaml /// </summary> public partial class mainwindow : window { public mainwindow() { initializecomponent(); datacontext = new mainwindowvm(); } }

and here viewmodel:

public class mainwindowvm : inotifypropertychanged { private observablecollection<string> _itemssource; public observablecollection<string> itemssource { { homecoming _itemssource; } set { _itemssource = value; onpropertychanged("itemssource"); } } private string _typedtext; public string typedtext { { homecoming _typedtext; } set { _typedtext = value; onpropertychanged("typedtext"); //check if typed text contained in items source list var searcheditem = itemssource.firstordefault(item => item.contains(_typedtext)); if (searcheditem == null) { //the item not found. } else { //do else } } } public mainwindowvm() { if (itemssource == null) { itemssource = new observablecollection<string>(); } (int = 0; < 25; i++) { itemssource.add("text" + i); } } public event propertychangedeventhandler propertychanged; protected virtual void onpropertychanged(string propertyname) { propertychangedeventhandler handler = propertychanged; if (handler != null) handler(this, new propertychangedeventargs(propertyname)); } protected bool setfield<t>(ref t field, t value, string propertyname) { if (equalitycomparer<t>.default.equals(field, value)) homecoming false; field = value; onpropertychanged(propertyname); homecoming true; } }

i hope helps.

wpf combobox

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -