PdfViewer - Customize Menu items

Hi

This solution proposed by Synfusion has stopped working with the latest version. Can you provide a new solution

//Get the instance of the toolbar using its template name 

DocumentToolbar toolbar = pdfViewerControl.Template.FindName("PART_Toolbar", pdfViewerControl) as DocumentToolbar; 
//Get the instance of the open file button using its template name 
Button openButton = (Button)toolbar.Template.FindName("PART_ButtonOpen", toolbar); 
//Set false to disable the button.  
openButton.IsEnabled = false; 
//Get the instance of the left pane using its template name 
OutlinePane outlinePane = pdfViewerControl.Template.FindName("PART_OutlinePane", pdfViewerControl) as OutlinePane; 
//Get the instance of the thumbnail button using its template name 
ToggleButton thumbnailButton = (ToggleButton) outlinePane.Template.FindName("PART_ThumbnailButton", outlinePane); 
thumbnailButton.IsEnabled = false; 

Thanks,



5 Replies 1 reply marked as answer

DD Divya Dhayalan Syncfusion Team July 29, 2021 09:06 AM UTC

Hi Josep, 
 
Thank you for contacting Syncfusion support. 
 
In the release 2020 Volume 4 release (18.4 version), we have added “Save” support in our control. On the basis of user convenience, we have grouped the File Menu items (Open, Save, Save As and Print) in the context menu of File Tools toggle button. The Open tool is now changed from Button control (“PART_ButtonOpen”) to Menu Item control (“PART_OpenMenuItem”).  
 
Please refer to the below UG link for the changes in the UI template for OpenMenuItem. 
 
Please let us know if the provided details helpful or if you need any further assistance on this. 
 
Regards, 
Divya 



JM jmaren July 29, 2021 01:16 PM UTC

Hi, Thanks for your answer but the problem is not the name change of button control, the problem is that it gives an exception

Error.png


Thanks in advance



DD Divya Dhayalan Syncfusion Team July 30, 2021 10:38 AM UTC

Hi Josep, 
 
Based on the provided screen shot, we can see the “System.NullreferenceException” is thrown because of the DocumentToolbar template name is incorrect. As we have mentioned in our previous update the Open tool is now changed from Button control (“PART_ButtonOpen”) to Menu Item control (“PART_OpenMenuItem”) because of the added feature for “Save As” menu. 
 
Please find the UI difference before and after the Save As Feature implementation 
Before 2020 Volume 4 release (18.4 version) release 
After 2020 Volume 4 release (18.4 version) release 
 
 
 
Please refer the below code snippet for the change 
 
// Get the instance of the toolbar using its template name  
            DocumentToolbar toolbar = pdfViewer.Template.FindName("PART_Toolbar", pdfViewer) as DocumentToolbar; 
 
            // Get the instance of the file menu button using its template name. 
            ToggleButton FileButton = (ToggleButton)toolbar.Template.FindName("PART_FileToggleButton", toolbar); 
 
            //Get the instance of the file menu button context menu and the item collection. 
            ContextMenu FileContextMenu = FileButton.ContextMenu; 
            foreach (MenuItem FileMenuItem in FileContextMenu.Items) 
            { 
                //Get the instance of the open menu item using its template name and disable its visibility. 
                if (FileMenuItem.Name == "PART_OpenMenuItem") 
                { 
                    FileMenuItem.Visibility = Visibility.Collapsed; 
                } 
            }            
 
 
We have also created a sample for your reference which can be downloaded from the below link, 
 
Please let us know whether the provided details and sample are helpful or if you need any further assistance on this. 
 
Regards, 
Divya 


Marked as answer

JM jmaren August 3, 2021 05:27 AM UTC

Thanks for your help, problem solved.


  Regards,



DD Divya Dhayalan Syncfusion Team August 4, 2021 06:05 AM UTC

Hi Josep, 
 
Most Welcome. Please let us know if you need any further assistance on this. 
 
Regards, 
Divya 


Loader.
Up arrow icon