GraphControl ApplyTemplate() not being called...

Feb 2, 2012 at 7:45 PM
Edited Feb 2, 2012 at 7:46 PM


In the Silverlight Graphlight.Demo, the GraphControl is a child of a TabControl. 
In my test application, I want just the GraphControl, not the parent TabControl, or
combo that allows you to switch graphs.

So, I have the following in my xaml.

    <Grid x:Name="LayoutRoot">
            <RowDefinition Height="*" />

        <Drawing:GraphControl x:Name="ctrlGraph" Graph="{Binding Graph, Mode=TwoWay}" />
Upon execution, the vertices would stack on one another, and none of the edges would render. There was also an exception 
being thrown in the GraphControl.addEdge() method concerning a null _graphItems. If I added the GraphControl as a child of the TabControl,
everything would work.

I've tracked this down to the fact that OnApplyTemplate() is not being called before the onLoaded() event is handled, resulting in null
_graphItems object during the Layout().

On the silverlight forums, I came across this post, where a MS Developer states we should call ApplyTemplate() in our Loaded handling method
because it is not guaranteed that the OnApplyTemplate() method is called before the Loaded handling in Silverlight.

        void onLoaded(object sender, RoutedEventArgs e)
          // New...

            if (!_isLoaded)
                _isLoaded = true;

Graphlight developers, does this make any sense? Is there another/better way for me to handle this?