Use local images in Webbrowser control

前端 未结 4 520
情深已故
情深已故 2020-11-29 13:06

I\'m using a Webbrowser Control in my Wp7 app, but I can\'t seem to put images that are in the App directory, in the webbrowser.

I\'ve put some images in a folder in

4条回答
  •  广开言路
    2020-11-29 14:07

    well you can used dynamic images by concatenate the above given Paul example application update the array dynamically,

    string[] files = {
            "readme.htm", "desert.jpg", "sample.jpg"
        };
    

    and before to write to isolated you can delete the existing one

           private void SaveFilesToIsoStore()
        {
            //These files must match what is included in the application package,
            //or BinaryStream.Dispose below will throw an exception.
            string[] files = {
            "readme.htm", "desert.jpg", "sample.jpg"
        };
    
            IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
            if(isoStore.FileExists(files[0]))
            {
                isoStore.DeleteFile(files[0]);
            }
    
                foreach (string f in files)
                {
                    StreamResourceInfo sr = Application.GetResourceStream(new Uri(f, UriKind.Relative));
                    using (BinaryReader br = new BinaryReader(sr.Stream))
                    {
                        byte[] data = br.ReadBytes((int)sr.Stream.Length);
                        SaveToIsoStore(f, data);
                    }
                }
            }
    
    
        private void SaveToIsoStore(string fileName, byte[] data)
        {
            string strBaseDir = string.Empty;
            string delimStr = "/";
            char[] delimiter = delimStr.ToCharArray();
            string[] dirsPath = fileName.Split(delimiter);
    
            //Get the IsoStore.
            IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
    
            //Re-create the directory structure.
            for (int i = 0; i < dirsPath.Length - 1; i++)
            {
                strBaseDir = System.IO.Path.Combine(strBaseDir, dirsPath[i]);
                isoStore.CreateDirectory(strBaseDir);
            }
    
            //Remove the existing file.
            if (isoStore.FileExists(fileName))
            {
                isoStore.DeleteFile(fileName);
            }
    
            //Write the file.
            using (BinaryWriter bw = new BinaryWriter(isoStore.CreateFile(fileName)))
            {
                bw.Write(data);
                bw.Close();
            }
        }
    

提交回复
热议问题