我有一个wpf项目。如何从我的视图模型中访问我视图中的FlowDocumentReader控件?我想从视图模型中设置其Document属性。我试过这种方法:
private static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
{
if (depObj != null)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
if (child != null && child is T)
{
yield return (T)child;
}
foreach (T childOfChild in FindVisualChildren<T>(child))
{
yield return childOfChild;
}
}
}
}
但它不适用于FlowDocumentReader。
以下是我一直在使用它的方式:
foreach (FlowDocumentReader panel in FindVisualChildren<FlowDocumentReader>(parentWindow))