0

我有一个 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))
4

0 回答 0