开发者

Hide WPF DocumentViewer toolbar programmatically

开发者 https://www.devze.com 2023-04-01 20:14 出处:网络
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 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? 开发者_StackOverflow社区


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消