Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException when i call OpenFile method #19

Open
jlpuma24 opened this issue May 7, 2018 · 13 comments
Open

NullReferenceException when i call OpenFile method #19

jlpuma24 opened this issue May 7, 2018 · 13 comments

Comments

@jlpuma24
Copy link

jlpuma24 commented May 7, 2018

Hi, a have a couples of issues regarding the OpenFile method calls, i create my component like this:

image

After that i call this method:

image

When the route of PDF on my computer and gives me NullReferenceException

Can you help me with this? Thanks!

@jlpuma24
Copy link
Author

jlpuma24 commented May 8, 2018

@reliak can you help me please? Thanks a lot

@Minimum006
Copy link

I guess you have opened your pdf file in Loaded event. Maybe you should use this.UpdateLayout() to force UI to update, so visualtree can find the scrollview which is the templatechild of inner panel

@seahandsome
Copy link

@jlpuma24 Hi, how did you solve this problem?

@focussing
Copy link

Hi, I have the same issue overhere, it already took me hours.

My application consists of tabPages, let's say a Base tab and a Manual tab for displaying PDF manual files.
The first time I switch from BaseTab to ManualTab I get the exception, but when I switch back to BastTab and to ManualTab a second time, it displays the PDF beautifully!

Visual Studio 2015, .NET 4.5.2, WPF application.

Any idea what I am doing wrong?

@focussing
Copy link

@reliak did you encounter this also?

@focussing
Copy link

@Minimum006 adding this.UpdateLayout() just before calling the OpenFile method does not help...

@focussing
Copy link

For the record; this is the error message.
System.NullReferenceException: Object reference not set to an instance of an object. at MoonPdfLib.ContinuousMoonPdfPanel.Load(IPdfSource source, String password) in C:\develop\moonpdf-master\src\MoonPdfLib\ContinuousMoonPdfPanel.xaml.cs:line 65 at MoonPdfLib.MoonPdfPanel.LoadPdf(IPdfSource source, String password) in C:\develop\moonpdf-master\src\MoonPdfLib\MoonPdfPanel.xaml.cs:line 232 at MoonPdfLib.MoonPdfPanel.Open(IPdfSource source, String password) in C:\develop\moonpdf-master\src\MoonPdfLib\MoonPdfPanel.xaml.cs:line 207 at MoonPdfLib.MoonPdfPanel.OpenFile(String pdfFilename, String password) in C:\develop\moonpdf-master\src\MoonPdfLib\MoonPdfPanel.xaml.cs:line 189

@focussing
Copy link

focussing commented Feb 14, 2020

@Minimum006 I see in the debugger that the following code is causing the exception;
this.virtualPanel and this.scrollViewer are null the first time this is called.

        {
            this.virtualPanel = VisualTreeHelperEx.FindChild<CustomVirtualizingPanel>(this);
            this.scrollViewer = VisualTreeHelperEx.FindChild<ScrollViewer>(this);
            this.virtualPanel.PageRowBounds = this.parent.PageRowBounds.Select(f => f.SizeIncludingOffset).ToArray();
            this.imageProvider = new PdfImageProvider(source, this.parent.TotalPages,
                                        new PageDisplaySettings(this.parent.GetPagesPerRow(), this.parent.ViewType, this.parent.HorizontalMargin, this.parent.Rotation),
                                        password: password);

            if (this.parent.ZoomType == ZoomType.Fixed)
                this.CreateNewItemsSource();
            else if (this.parent.ZoomType == ZoomType.FitToHeight)
                this.ZoomToHeight();
            else if (this.parent.ZoomType == ZoomType.FitToWidth)
                this.ZoomToWidth();

            if (this.scrollViewer != null)
            {
                this.scrollViewer.Visibility = System.Windows.Visibility.Visible;
                this.scrollViewer.ScrollToTop();
            }
        }

@netcore-jroger
Copy link

The author has not been active on github for several years, modify it yourself.

@focussing
Copy link

@netcore-jroger thank you for your message; I am already digging into it; not a clue yet where to fix it

@netcore-jroger
Copy link

netcore-jroger commented Feb 18, 2020

@focussing You can look at the example. I used this component many years ago but did not encounter your problem.But I have no environment now

@salzschneider
Copy link

Hi,

I got this error message when I called the TogglePageDisplay function. The value of the PageRowDisplay attrib in the xaml was SinglePageRow. I changed the PageRowDisplay to ContinuousPageRows and removed the TogglePageDisplay call. It's just a workaround, of course, but it's working for me.

@PineappleUFO
Copy link

Hi,
May help someone :)
ran into the same problem, if you want to use PageRowDisplay="ContinuiusPageRows" and you get an error when opening the file, check that you don't use Visible="Collapsed" on the MoonPdfPanel element, use Hidden

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants