you are right, not perfect though working here I present my final solution (for the ones that search the internet desperately :)
// http://www.beacosta.com/blog/?p=41
private T GetObjectOfTypeInVisualTree<T>(DependencyObject dpob) where T : DependencyObject
{
int count = VisualTreeHelper.GetChildrenCount(dpob);
for (int i = 0; i < count; i++)
{
DependencyObject child = VisualTreeHelper.GetChild(dpob, i);
T childAsT = child as T;
if (childAsT != null)
{
return childAsT;
}
childAsT = GetObjectOfTypeInVisualTree<T>(child);
if (childAsT != null)
{
return childAsT;
}
}
return null;
}
private void ManualStartAnimation(string templateName, string elementName, RoutedEventArgs eventArgs)
{
// this works too
// http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/4a04938b-690b-4bd0-969a-6dc4f6d6fda5/
// this is implemented
// http://joshsmithonwpf.wordpress.com/2007/06/28/how-to-use-findname-with-a-contentcontrol/
// together with this (GetObjectOfTypeInVisualTree)
// http://www.beacosta.com/blog/?p=41
DataTemplate \_dt = (DataTemplate)this.FindResource(templateName);
if (\_dt != null)
{
// reminder: displayContent is the ContentControl
ContentPresenter \_cp = GetObjectOfTypeInVisualTree<ContentPresenter>(this.displayContent);
if (\_cp != null)
{
UIElement \_element = (UIElement)\_dt.FindName(elementName, \_cp);
if (\_element != null)
{
\_element.RaiseEvent(eventArgs);
}
}
}
}
public void ShowLogin()
{
->kick ManualStartAnimation("flipItemTemplate", "frontHost", new RoutedEventArgs(FlipToLoginEvent));
}