문제

This question has a solution: How do you hide a WPF DocumentViewer's menu bars?

However, it only allows hiding the toolbar through XAML. I need to get this done programmatically.

This answer: WPF: How can I remove the searchbox in a DocumentViewer? hides the search bar programmatically.

How do I hide the main toolbar via non-xaml code?

도움이 되었습니까?

해결책

There is nothing in a DocumentViewer which ensures that the toolbar is even there, that being the case a programmatic manipulation of the control at run-time to remove a toolbar which may or may not exist might not be such a good idea. Of course you can do some null-checking and exception handling but that is not very clean either.

For the default aero template the following code will knock out the toolbar:

var contentHost = viewer.Template.FindName("PART_ContentHost", viewer) as ScrollViewer;
var grid = contentHost.Parent as Grid;
grid.Children.RemoveAt(0);

I remove the toolbar indirectly as it is not a PART, this is the reason why it may not even exist in some themes.

Ideally you should override the template completely.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top