0

I am developing custom control which includes WebBrowser control inside its control template. creating custom control and accessing WebBrowser inside control template works without any problem but I have a situation where OnAppyTemplate method needs to dynamically load HTML file which is inside same custom control library DLL. here is the code I am using at the moment but when I try to access file streamResourceInfo is always null

    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();

        _host = GetTemplateChild("PART_BrowserHost") as WebBrowser;
        if (_host == null) return;
        _host.LoadCompleted += HostOnLoadCompleted;

        var uri = new Uri(@"pack://application:,,,/Taicodev.Shark.Controls;component/EpubReader/Resources/Book.html", UriKind.Absolute);
        var streamResourceInfo = Application.GetContentStream(uri);

        var source = streamResourceInfo.Stream;
        _host.NavigateToStream(source);
    }
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Rati_Ge
  • 1,262
  • 2
  • 15
  • 37

1 Answers1

0

Is the build action for the file Resource or is it EmbeddedResource? The latter would require using GetManifestResourceStream and not a pack Uri. If it is a Resource have you verified that that is the correct name for the resource? E.g. looking at the resources of that assembly in reflector/ilspy.

AndrewS
  • 6,054
  • 24
  • 31
  • Well its' build action is set to Resource not EmbeddedResource. – Rati_Ge Feb 14 '13 at 18:23
  • Then I would use GetResourceStream and not GetContentStream. – AndrewS Feb 15 '13 at 03:05
  • So u generally suggest changing Application.GetContentStream(uri); – Rati_Ge Feb 15 '13 at 11:53
  • Well I haven't used GetContentStream but I have successfully used GetResourceStream to access a Resource embedded stream. Check out [this page](http://msdn.microsoft.com/en-us/library/aa970494.aspx) for a distinction. – AndrewS Feb 15 '13 at 15:57