We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Add stamp to custom stamp bar is not working


I am using this vb.net code to add a custom stamp durch start of my application.

This will just add an empty stamp (cannot see the image in the toolbar, just an empty element). Clicking on thes empty stamp will result in a System.NullReferenceException.

Here is my code:

Private Sub pdfViewer_Loaded(sender As Object, e As RoutedEventArgs) Handles pdfViewer.Loaded

        Dim toolbar As DocumentToolbar = TryCast(pdfViewer.Template.FindName("PART_Toolbar", pdfViewer), DocumentToolbar)

        Dim stampButton As ToggleButton = CType(toolbar.Template.FindName("PART_Stamp", toolbar), ToggleButton)

        Dim customMenuItem As MenuItem = CType(stampButton.ContextMenu.Items(1), MenuItem)

        'Create the instance of the image

        Dim image As System.Windows.Controls.Image = New System.Windows.Controls.Image()

        Dim BitmapImage As BitmapImage = New BitmapImage()


        BitmapImage.CacheOption = BitmapCacheOption.Default

        BitmapImage.UriSource = New Uri("image.png", UriKind.RelativeOrAbsolute)


        'Create the viewbox And the image.

        Dim viewbox As Viewbox = New Viewbox()

        viewbox.Child = image

        Dim _grid As New System.Windows.Controls.Grid()



End Sub

What I am doing wrong?

Thank you in advance. Marco

2 Replies 1 reply marked as answer

KG Krithika Ganesan Syncfusion Team October 18, 2022 09:15 AM

Hi Marco,


Thank you for contacting Syncfusion Support. 


From the Shared code snippet, we come to know that as image source, width and height property values are not assigned. So you are getting null reference exception. Please use the below code snippet and shared sample to overcome this null reference exception.


image.Source = BitmapImage

If image.Width.Equals(Double.NaN) AndAlso image.Height.Equals(Double.NaN) Then

      image.Height = image.Source.Height

      image.Width = image.Source.Width

End If


Please let us know is you need any clarification, or you have any concerns.




Attachment: PdfViewerWPF_aa545791.zip

Marked as answer

MU Marco Uffelmann replied to Krithika Ganesan October 25, 2022 09:26 AM

Thank you Krithika. This was the solution.

Live Chat Icon For mobile
Up arrow icon