我正在DocumentViewer中显示一个xps文档. 在程序中,DocumentViewer旁边有一个树状视图列表,当您选择每个项目时,它应将xps文件导航到特定位置(就像pdf书签一样). 问题是我必须将VerticalScrollbar位置设置为特殊位置,并使其即使通过页面缩放等也唯一且稳定. 为此,我尝试通过比率(偏移=比率* maxoffset)设置位置,但是找不到maxoffset,实际上"ScrollViewer.Content.ActualHeight"与滚动条末尾的偏移不同. 我的代码是:
Hi, I am showing a xps document in a DocumentViewer. In the program there is a treeview list next to the DocumentViewer that when you select each item it should navigate the xps file to specifice place(just like pdf bookmark). The problem is i have to set the VerticalScrollbar position to a special position and make it unique and stable even by page zoom and etc. for that i tried to set the position by the ratio (offset = ratio * maxoffset) but cant find the maxoffset, actually the "ScrollViewer.Content.ActualHeight" is different from the offset at the end of the scrollbar. my code is:
ScrollViewer dvScrollViewer = documentViewer.Template.FindName("PART_ContentHost", documentViewer) as ScrollViewer; dvScrollViewer.ScrollToEnd(); MessageBox.Show(dvScrollViewer.VerticalOffset.ToString()); MessageBox.Show((dvScrollViewer.Content as FrameworkElement).ActualHeight.ToString());但是第一个消息是86667.307 第二个是573.696 有帮助吗? 很长的问题和英语对不起,:D
But the firs message is 86667.307 and the second one : 573.696 any Help? sorry for the long question and the english :D thanks.
推荐答案嗨. 请尝试以下操作: dvScrollViewer.ScrollToEnd(); dvScrollViewer.UpdateLayout(); MessageBox.Show(dvScrollViewer.VerticalOffset.ToString()); MessageBox.Show((dvScrollViewer.Content as FrameworkElement).ActualHeight.ToString()); 问候. Hi. Please try this: dvScrollViewer.ScrollToEnd(); dvScrollViewer.UpdateLayout(); MessageBox.Show(dvScrollViewer.VerticalOffset.ToString()); MessageBox.Show((dvScrollViewer.Content as FrameworkElement).ActualHeight.ToString()); Regards.
更多推荐
查找DocumentViewer的ScrollViewer的最大偏移量
发布评论