WPF 的 FlowDocumentScrollViewer滚动到最底下的方法

官网上好像并没有直接给相应的接口和方法。
发现一种有效的方法:
先说方法:

ScrollViewer sv = flowScrollViewer.Template.FindName("PART_ContentHost", flowScrollViewer) as ScrollViewer;
sv.ScrollToEnd();

其中flowScrollViewer是控件FlowDocumentScrollViewer的名称。

原理:

该控件的ControlTemplate如下:

可以看到里面的ScrollViewer的名称正是PART_ContentHost,所以可以取到这个控件,然后进行操作。

而怎么查看它的ControlTemplate,可以查看我的github上的代码:
https://github.com/JohnYang1210/WPFTestDemo

中的ControlDetailTemplateShow.xaml即可。

posted @ 2022-11-02 14:59  JohnYang819  阅读(265)  评论(0编辑  收藏  举报