Hi Stoyo
I am having problems with UpdateVisuals -
As I described previously, I have a derived class from ShapeNode and this class has its own genric.xaml file having following object -
<Grid x:Name="ChildGrid" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
This object stored in global class level variable in OnApplyTemplate function as below -
childGrid = (Grid)base.GetTemplateChild("ChildGrid");
In my UpdateVisual function I have following code -
protected override void UpdateVisuals()
{
if ((this.childGrid != null) && (childGridItems == null))
{
childGridItems = new Grid();
childGridItems.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30, GridUnitType.Star) });
childGridItems.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30, GridUnitType.Star) });
childGridItems.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30, GridUnitType.Star) });
childGridItems.ShowGridLines = true;
childGrid.Children.Add(childGridItems);
}
base.UpdateVisuals();
}
If this.ChildGrid != null check is not added, I get exception, since UpdateVisual gets triggered from base class when bounds are set. [ Seen from Stack ]
Adding this.ChildGrid != null, check doesn't show me the grid which is added, when shapenode is shown on screen. If I try to resize node, then the child grid is visible since at that time again "UpdateVisual" gets triggered.
Can you tell me at what location should I do above coding [ For eq. If i need to raise event where should I do it ? ]
The childGrid object doesn't get set unless and until, OnApplyTemplate function gets triggered.
Or SetBounds function should not trigger UpdateVisual if "OnApplyTemplate" doesn't get executed and it should be executed once OnApplyTemplate gets executed.
Also - I shouldn't execute above code in "OnApplyTemplate" because when this code is executed, it is possible that shape is not set.
Let me know, How i achive this ?
-Regards
Rajesh