public T GetVisualChild<T>(System.Windows.DependencyObject parent, System.Func<T, bool> predicate) where T : System.Windows.Media.Visual
{
int numVisuals = System.Windows.Media.VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < numVisuals; i++)
{
System.Windows.DependencyObject v = (DependencyObject)System.Windows.Media.VisualTreeHelper.GetChild(parent, i);
T child = v as T;
if (child == null)
{
child = GetVisualChild<T>(v, predicate);
if (child != null)
{
return child;
}
}
else
{
if (predicate(child))
{
return child;
}
}
}
return null;
}
Button btnTopMost= GetVisualChild(this, v => v.Name == "btnTopMost");
"this" is your MainWindow class instance. "btnTopMost" in Generic.xaml defined like this x:Name="btnTopMost".
In WPF project, use this code, you can access Generic.xaml's control that in style. I think it may help you, good luck.