Items.Add("changing event raised");
//XElement newEl = (XElement)xsender;
//listBox1.Items.Add(" Sender: " + newEl.Name);
listBox1.Items.Add(" ObjectChange: " + cea.ObjectChange);
}
);
empXML.Element("Employee").Element("Title").Value = "Geek";
Execute the code, and then press F10 to step through it. You??™ll notice that it executes the Changing event
as a whole, then it executes the last line, which updates the value of the Title element. When you press
F10 on the last line, the execution enters the Changing event and goes through it not once, but twice.
Why? Take a look at the output produced by the code in the event:
Changing event raised
ObjectChange: Remove
169
Part II: LINQ to XML
Changing event raised
ObjectChange: Add
There??™s the answer: An update is really a delete with an Add and Insert. Slick.
Changed
The Changed event fires when a change is made to an XObject or any of its descendants. In other words,
it fires when a change on an element or attribute, or any of its descendants, is complete.
For example, the following code defines an XML tree, defines a Changing event and Changed event, and
applies both events to the root node.
Pages:
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293