I am having troubles understanding when the OnRender method is invoked.
Consider my example:
I have a class SomeElement deriving from FrameworkElement which overrides the OnRender method.
Suppose I have a Grid grid
. What I would expect is that
var someElement = new SomeElement();
grid.AddVisualChild(someElement);
someElement.InvalidateVisual();
would cause the SomeElement.OnRender method to be triggered. It doesn't in my case, but the following does:
var someElement = new SomeElement();
grid.Children.Add(new SomeElement());
someElement.InvalidateVisual();
So my question is why someElement
isn't drawn when it's added solely to the visual tree. What is the importance of adding it to the property Children
?
And more generally, what how is OnRender called? Via the visual tree, or Children
property, or?