Telerik PdfViewer - 绑定到 PDF 源
Telerik PdfViewer - Binding to a PDF source
我也试过 telerik 网站上的示例,但无济于事。所以我有这个代码:
public ICommand EmailPopUpCmd { get; set; }
private void EmailPopUp(object sender) {
//ToDo: pdf viewer pop up
selectedDataRow = (DataRow)sender;
var window = new Window();
window.Content = new EmailView() { DataContext = this}; //shares the same data context
MemoryStream str = new MemoryStream();//= new MemoryStream(pdfAsByteArray);//new System.Uri(@"pack://application:,,,/Resources/TestPDF.pdf", System.UriKind.RelativeOrAbsolute);
using(FileStream fs = File.OpenRead(@"C:\Source\UI.MailViewer\Resources\TestPDF.pdf")) {
str.SetLength(fs.Length);
fs.Read(str.GetBuffer(),0, (int)fs.Length);
}
AttachmentPath = new PdfDocumentSource(str);
if (window.ShowDialog() == true) {
//from child back to parent
}
}
C:\Source\UI.MailViewer\Resources\TestPDF.pdf
Is where my PDF is located and I bind it to the UI as follow:
telerik:RadPdfViewer x:Name="pdfEmailViewer"
Grid.Row="2"
DocumentSource="{Binding AttachmentPath,Converter={StaticResource DebugConverter}}">
现在使用这个,我得到一个对象未设置为实例错误。知道为什么吗?使用调试转换器,创建的PDF文档的值为空,为什么会这样?
好的,为了帮助其他用户,我在 telerik 论坛上找到了这个:(Telerik Forum Link)
为了使 RadPdfViewer 在 WinForms 应用程序中工作,还需要做一件事:您应该确保在初始化用户控件之前初始化 Application.Current 属性,例如通过在用户控件的构造函数中添加此代码:
public PdfViewerControl() {
if (Application.Current == null)
new Application();
InitializeComponent();
}
这在 WPF 中也对我有用。
我也试过 telerik 网站上的示例,但无济于事。所以我有这个代码:
public ICommand EmailPopUpCmd { get; set; }
private void EmailPopUp(object sender) {
//ToDo: pdf viewer pop up
selectedDataRow = (DataRow)sender;
var window = new Window();
window.Content = new EmailView() { DataContext = this}; //shares the same data context
MemoryStream str = new MemoryStream();//= new MemoryStream(pdfAsByteArray);//new System.Uri(@"pack://application:,,,/Resources/TestPDF.pdf", System.UriKind.RelativeOrAbsolute);
using(FileStream fs = File.OpenRead(@"C:\Source\UI.MailViewer\Resources\TestPDF.pdf")) {
str.SetLength(fs.Length);
fs.Read(str.GetBuffer(),0, (int)fs.Length);
}
AttachmentPath = new PdfDocumentSource(str);
if (window.ShowDialog() == true) {
//from child back to parent
}
}
C:\Source\UI.MailViewer\Resources\TestPDF.pdf Is where my PDF is located and I bind it to the UI as follow:
telerik:RadPdfViewer x:Name="pdfEmailViewer"
Grid.Row="2"
DocumentSource="{Binding AttachmentPath,Converter={StaticResource DebugConverter}}">
现在使用这个,我得到一个对象未设置为实例错误。知道为什么吗?使用调试转换器,创建的PDF文档的值为空,为什么会这样?
好的,为了帮助其他用户,我在 telerik 论坛上找到了这个:(Telerik Forum Link)
为了使 RadPdfViewer 在 WinForms 应用程序中工作,还需要做一件事:您应该确保在初始化用户控件之前初始化 Application.Current 属性,例如通过在用户控件的构造函数中添加此代码:
public PdfViewerControl() {
if (Application.Current == null)
new Application();
InitializeComponent();
}
这在 WPF 中也对我有用。