flowdocument reader中有一個pagenumber屬性,但該屬性是隻讀的。有什麼辦法可以在flowdocument reader中獲得特定的頁碼。請幫助。如何通過WPF中的代碼在flowdocument閱讀器中獲取特定頁碼?
謝謝。
flowdocument reader中有一個pagenumber屬性,但該屬性是隻讀的。有什麼辦法可以在flowdocument reader中獲得特定的頁碼。請幫助。如何通過WPF中的代碼在flowdocument閱讀器中獲取特定頁碼?
謝謝。
如果您願意將用戶限制爲分頁顯示,請改爲使用FlowDocumentPageViewer:它具有GoToPage()方法。出於某種原因GoToPage()似乎沒有在FlowDocumentReader上提供;我猜這是因爲FlowDocumentReader並不總是處於一個有意義的分頁模式(用戶可以選擇一個連續的滾動視圖),並且當它有意義時提供它自己的UI。
您可以嘗試將它發送給NavigationCommands.GoToPage命令,但這僅記錄爲在FlowDocumentPageViewer和DocumentViewer上工作;我沒有在FlowDocumentReader上測試過它。
如果你把包含在FlowDocumentReader賽道上的FlowDocument的塊, 比你可以簡單地使用:
// Getting a block by index
YourReader.Document.Blocks.ElementAt(index).BringIntoView();
// Showing Last Block
YourReader.Document.Blocks.LastBlock.BringIntoView();
// Showing the last Inline
(YourReader.Document.Blocks.LastBlock as Paragraph).Inlines.LastInline.BringIntoView();
這工作僅在FlowDocumentReader頁面ViewingModes。
如果您對子級喜歡在滾動模式這樣做,你必須沿着可視化樹和搜索的ScrollViewer, 財產以後這樣的:
public static ScrollViewer FindScroll(Visual visual)
{
if (visual is ScrollViewer)
return visual as ScrollViewer;
ScrollViewer searchChiled = null;
DependencyObject chiled;
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(visual); i++)
{
chiled = VisualTreeHelper.GetChild(visual, i);
if (chiled is Visual)
searchChiled = FindScroll(chiled as Visual);
if (searchChiled != null)
return searchChiled;
}
return null;
}
ScrollViewer scroller = FindScroll(YourReader as Visual);
if (scroller != null)
(scroller as ScrollViewer).ScrollToBottom();
感謝您的答覆,讓我看看讀者。 – Ershad 2009-10-26 05:15:04
再次感謝。我將使用FlowDocumentPageViewer .. – Ershad 2009-10-26 05:18:25