Use this Helper method in code behind
T GetVisualChild<t>(DependencyObject parent, string name) where T : Visual
{
T child = default(T);
int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < numVisuals; i++)
{
Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
child = v as T;
if (child == null)
{
child = GetVisualChild<t>(v, name);
}
if (child != null)
{
break;
}
}
return child;
}
</t></t>
You just Need is
for eg. Declare Your Image First in your code behind as
Image ImgAlert=new Image();
in your constructor or Loaded method
then on your event You can call this method by
ImgAlert=GetVisualChild<treeview>(this, "ImgAlert");
</treeview>