I have a textbox, when its content changed, I want to query the xml file for elements that match the text in the textbox and display the result in a listbox.
My current code is:
private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
{
var xElem = XElement.Load("ProductTable.xml");
...
How should I code so that Load is called only once? As is, each time a keystroke is entered, the xml file is (re)loaded. Thanks.
Move
xElemto be your class’s field. Then inTextChangedhandler check fornull: