I'm trying to using MVVM binding for the pdfviewer but the document always turns out blank. I'm querying a DB field that contains the bytes of the PDF file and I'm trying to get it to display in the viewer (I've confirmed that the file is not malformed and it displays fine if I save it as a PDF to my desktop).
Here are my MVVM properties:
private RadFixedDocument _currentDocument;
public RadFixedDocument CurrentDocument
{
get => _currentDocument; set => this.RaiseAndSetIfChanged(ref _currentDocument, value);
}
Here is the method I'm using to populate the CurrentDocument property:
var sqlStr = @"select top 1 * from FileManager order by ID desc;";
var file = await con.QuerySingleAsync<FMFile>(sqlStr);
var fileBytes = file.FileContent.ToArray(); // this is type byte[] - I confirmed that it has the correct contents
var ms = new MemoryStream(fileBytes); // ms gets filled properly
FormatProviderSettings settings = new FormatProviderSettings(ReadingMode.AllAtOnce);
PdfFormatProvider provider = new PdfFormatProvider(ms, settings);
CurrentDocument = provider.Import();
And here is how my XAML looks:
<telerik:RadPdfViewerToolBar RadPdfViewer="{Binding ElementName=pdfViewer, Mode=OneTime}" />
<telerik:RadPdfViewer x:Name="pdfViewer"
Grid.Row="1"
DocumentSource="{Binding CurrentDocument, Mode=TwoWay}" />
However, nothing get's displayed in the viewer. I confirmed that my VM is hooked up correctly as other property display just fine. Any advice would be appreciated.