public partial class MainPage : UserControl
{
private const string DocumentPath = "CageManagementFeatures.docx";
private RadDocumentBindingSource bindingSource = new RadDocumentBindingSource();
private DocumentViewManager viewManager;
public MainPage()
{
InitializeComponent();
this.viewManager = (DocumentViewManager)this.Resources["viewManager"];
}
private void LoadDocument(Stream stream, string extension)
{
RadDocument doc;
IDocumentFormatProvider provider = DocumentFormatProvidersManager.GetProviderByExtension(extension);
if (provider != null)
{
doc = provider.Import(stream);
}
else
{
MessageBox.Show("Unknown format.");
return;
}
doc.Measure(RadDocument.MAX_DOCUMENT_SIZE);
doc.Arrange(new RectangleF(PointF.Empty, doc.DesiredSize));
doc.LayoutMode = DocumentLayoutMode.Paged;
doc.DefaultPageLayoutSettings.Width = 320 / 0.7F;
doc.DefaultPageLayoutSettings.Height = 390 / 0.7F;
doc.SectionDefaultPageMargin = new Padding(55);
doc.Sections.First.PageMargin = new Padding(55);
doc.UpdateLayout();
this.book.RightPageIndex = 0;
this.viewManager.Document = doc;
bindingSource.Document = doc;
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
<!-- NULL ERROR OCCURS IN THIS LINE-->
using (Stream stream = Application.GetResourceStream(this.GetResourceUri(DocumentPath)).Stream)
{
this.LoadDocument(stream, ".docx");
}
this.book.ItemsSource = bindingSource;
}
private Uri GetResourceUri(string resource)
{
AssemblyName assemblyName = new AssemblyName(this.GetType().Assembly.FullName);
string resourcePath = "/" + assemblyName.Name + ";component/" + resource;
Uri resourceUri = new Uri(resourcePath, UriKind.Relative);
return resourceUri;
}
private void Simulation_Click(object sender, RoutedEventArgs e)
{
book.Visibility = Visibility.Collapsed;
radMediaPlayer1.Visibility = Visibility.Visible;
radMediaPlayer1.Play();
}
}
}
1. Why am I getting a Null Value when stepping through the code shows a
value in the GetResourceUri return value?
2. I have the document in a folder "Documents/Cage Management Features.docx"
which didn't work and so I placed it in the root folder and removed spaces,
but that didn't work either.
3. The mainpage.xaml is copied from the sample.
Any suggestions would be appreciated. Thank you.