The first, BeginInit(), is called
immediately after the element is instantiated. After BeginInit() is called, the XAML parser sets
all the element properties (and adds any content). The second method, EndInit(), is called
when initialization is complete, at which point the Initialized event fires.
nNote This is a slight simplification. The XAML parser takes care of calling the BeginInit() and EndInit()
methods, as it should. However, if you create an element by hand and add it to a window, it??™s unlikely that
you??™ll use this interface. In this case, the element raises the Initialized event once you add it to the window,
just before the Loaded event.
When you create a window, each branch of elements is initialized in a bottom-up fashion.
That means deeply nested elements are initialized before their containers. When the Initialized
event fires, you are guaranteed that the tree of elements from the current element down is
completely initialized. However, the element that contains your element probably isn??™t initialized,
and you can??™t assume that any other part of the window is initialized.
After each element is initialized, it??™s also laid out in its container, styled, and bound to a
data source, if required. After the Initialized event fires for the window, it??™s time to go on to the
next stage.
Pages:
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332