Ejemplo n.º 1
1
 public void LoadPost(string postFile)
 {
     FileStream fileStream = new FileStream(postFile, FileMode.Open);
     TextRange range = new TextRange(_postEdit.Document.ContentStart, _postEdit.Document.ContentEnd);
     range.Load(fileStream, DataFormats.Rtf);
     fileStream.Close();
 }
Ejemplo n.º 2
1
        /// <summary>
        /// Converts the XHtml content to XAML and sets the converted content in a flow document.
        /// </summary>
        /// <param name="document">The flow document in which the XHtml content has to be loaded.</param>
        /// <param name="text">The Unicode UTF-8 coded XHtml text to load.</param>
        /// <exception cref="InvalidDataException">When an error occured while parsing xaml code.</exception>
        public void SetText(FlowDocument document, string text)
        {
            try
            {
                if (!string.IsNullOrEmpty(text))
                {
                    XDocument xDocument = XDocument.Parse(text);
                    string xaml = HtmlToXamlConverter.ConvertXHtmlToXaml(xDocument, false);

                    TextRange tr = new TextRange(document.ContentStart, document.ContentEnd);
                    using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xaml)))
                    {
                        tr.Load(ms, DataFormats.Xaml);
                    }

                    _xHtml = text;
                }
            }
            catch (Exception e)
            {
                // todo tb: Logging
                //log.Error("Data provided is not in the correct Xaml or XHtml format: {0}", e);
                throw e;
            }
        }
Ejemplo n.º 3
0
        public static FlowDocument FlowDocumentFromBase64String(this string data)
        {

            FlowDocument FD = new FlowDocument();//Need to fix Possible MemLeak
            if (data == null) return FD;
            //FD = (FlowDocument)XamlReader.Parse(data);

            byte[] content;
            TextRange tr = new TextRange(FD.ContentStart, FD.ContentEnd);
            //convert string to MemoryStream   
            if (data.StartsWith("{"))
            {
                content = new byte[data.Length + sizeof(char)];
                Buffer.BlockCopy(data.ToCharArray(), 0, content, 0, content.Length);
                MemoryStream ms = new MemoryStream(content);
                tr.Load(ms, System.Windows.DataFormats.Rtf);
            }
            else
            {
                content = Convert.FromBase64String(data);
                MemoryStream ms = new MemoryStream(content);
                tr.Load(ms, System.Windows.DataFormats.XamlPackage);
            }
            return FD;
            //SQLData = ASCIIEncoding.Default.GetString(ms.ToArray());
            //You can save this data to SQLServer 
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Converts HTML document to RTF format; Places this RTF in RichTextBox;
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Start_Click(object sender, RoutedEventArgs e)
        {
            string htmlFile  = @"..\..\Sample.html";
            string rtfString = String.Empty;

            // Create an instance of the converter.
            SautinSoft.HtmlToRtf h = new HtmlToRtf();

            h.TextStyle.DefaultFontFamily = "Calibri";

            // Convert HTML to RTF.
            if (h.OpenHtml(htmlFile))
            {
                using (MemoryStream msRtf = new MemoryStream())
                {
                    // Convert HTML to RTF.
                    if (h.ToRtf(msRtf))
                    {
                        // Place the RTF into RichTextBox.
                        System.Windows.Documents.TextRange tr = new System.Windows.Documents.TextRange(
                            RtfControl.Document.ContentStart, RtfControl.Document.ContentEnd);
                        tr.Load(msRtf, DataFormats.Rtf);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.ShowDialog();
            fs = File.Open(new Uri(ofd.FileName).LocalPath, FileMode.Open);
            int length, offset;
            length = int.Parse(tbxlength.Text);
            offset = int.Parse(tbxoffset.Text);
            byte[] buffer = new byte[offset];
            fs.Read(buffer,0,offset);

            TextRange tr = new TextRange(tbxPrevious.Document.ContentStart, tbxPrevious.Document.ContentEnd);
            using(MemoryStream ms = new MemoryStream(buffer))
            {
                tr.Load(ms, DataFormats.Rtf);
            }

            buffer = new byte[length];
            fs.Read(buffer, 0, length);
            tr = new TextRange(tbxTarget.Document.ContentStart, tbxTarget.Document.ContentEnd);
            using (MemoryStream ms = new MemoryStream(buffer))
            {
                tr.Load(ms, DataFormats.Rtf);
            }

            buffer = new byte[fs.Length - fs.Position];
            fs.Read(buffer, 0, buffer.Length);
            tr = new TextRange(tbxNext.Document.ContentStart, tbxNext.Document.ContentEnd);
            using (MemoryStream ms = new MemoryStream(buffer))
            {
                tr.Load(ms, DataFormats.Rtf);
            }

            fs.Close();
        }
Ejemplo n.º 6
0
        private static string ConvertRtfToXaml(string rtfText)
        {
            var richTextBox = new RichTextBox();
            if (string.IsNullOrEmpty(rtfText)) return "";

            var textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);

            //Create a MemoryStream of the Rtf content

            using (var rtfMemoryStream = new MemoryStream())
            {
                using (var rtfStreamWriter = new StreamWriter(rtfMemoryStream))
                {
                    rtfStreamWriter.Write(rtfText);
                    rtfStreamWriter.Flush();
                    rtfMemoryStream.Seek(0, SeekOrigin.Begin);

                    //Load the MemoryStream into TextRange ranging from start to end of RichTextBox.
                    textRange.Load(rtfMemoryStream, DataFormats.Rtf);
                }
            }

            using (var rtfMemoryStream = new MemoryStream())
            {

                textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
                textRange.Save(rtfMemoryStream, DataFormats.Xaml);
                rtfMemoryStream.Seek(0, SeekOrigin.Begin);
                using (var rtfStreamReader = new StreamReader(rtfMemoryStream))
                {
                    return rtfStreamReader.ReadToEnd();
                }
            }
        }
Ejemplo n.º 7
0
        private static void OnBoundDocumentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RichTextBox box = d as RichTextBox;

            if (box == null)
                return;

            RemoveEventHandler(box);

            var bytes = e.NewValue as byte[];

            box.Document.Blocks.Clear();
            if(bytes != null && bytes.Length > 0)
            {
                
                TextRange textRange = new TextRange(box.Document.ContentStart, box.Document.ContentEnd);
                using (MemoryStream ms = new MemoryStream())
                {
                
                        ms.Write(bytes,0, bytes.Length);
                        textRange.Load(ms, DataFormats.Rtf); 
                }
            }


            AttachEventHandler(box);

        }
Ejemplo n.º 8
0
        private void RichTextBox_Drop(object sender, DragEventArgs e)
        {
            RichTextBox currentRichTextBox = TabItemManipulate.GetCurrentRichTextBox(_ControlBox);

            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] docPath = (string[])e.Data.GetData(DataFormats.FileDrop);

                var dataFormat = DataFormats.Text;


                System.Windows.Documents.TextRange range;
                System.IO.FileStream fStream;
                if (System.IO.File.Exists(docPath[0]))
                {
                    try
                    {
                        // Open the document in the RichTextBox.
                        range   = new System.Windows.Documents.TextRange(currentRichTextBox.Document.ContentStart, currentRichTextBox.Document.ContentEnd);
                        fStream = new System.IO.FileStream(docPath[0], System.IO.FileMode.OpenOrCreate);
                        range.Load(fStream, dataFormat);
                        fStream.Close();
                    }
                    catch (System.Exception)
                    {
                        //MessageBox.Show("File could not be opened. Make sure the file is a text file.");
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public static void AddBlock(Block from, FlowDocument to)
        {
            if (from != null)
              {
            //if (from is ItemsContent)
            //{
            //  ((ItemsContent)from).RunBeforeCopy();
            //}
            //else
            {
              TextRange range = new TextRange(from.ContentStart, from.ContentEnd);

              MemoryStream stream = new MemoryStream();

              System.Windows.Markup.XamlWriter.Save(range, stream);

              range.Save(stream, DataFormats.XamlPackage);

              TextRange textRange2 = new TextRange(to.ContentEnd, to.ContentEnd);

              textRange2.Load(stream, DataFormats.XamlPackage);
            }

              }
        }
Ejemplo n.º 10
0
        public static string ConvertRtfToXaml(string rtfText)
        {
            var richTextBox = new System.Windows.Controls.RichTextBox();
            if (string.IsNullOrEmpty(rtfText))
                return String.Empty;
            var textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
            using (var rtfMemoryStream = new MemoryStream())
            {
                using (var rtfStreamWriter = new StreamWriter(rtfMemoryStream))
                {
                    rtfStreamWriter.Write(rtfText);
                    rtfStreamWriter.Flush();
                    rtfMemoryStream.Seek(0, SeekOrigin.Begin);
                    textRange.Load(rtfMemoryStream, DataFormats.Rtf);
                }
            }

            using (var rtfMemoryStream = new MemoryStream())
            {
                textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
                textRange.Save(rtfMemoryStream, System.Windows.DataFormats.Xaml);
                rtfMemoryStream.Seek(0, SeekOrigin.Begin);
                using (var rtfStreamReader = new StreamReader(rtfMemoryStream))
                {
                    return rtfStreamReader.ReadToEnd();
                }
            }
        }
Ejemplo n.º 11
0
        private void AbrirMenuItem_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.DefaultExt = ".txt";
            dlg.Filter = "Text documents (.txt)|*.txt";

            Nullable<bool> result = dlg.ShowDialog();

            if (result == true)
            {

                    TextRange range;

                    System.IO.FileStream fStream;

                    if (System.IO.File.Exists(dlg.FileName))
                    {

                        range = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd);

                        fStream = new System.IO.FileStream(dlg.FileName, System.IO.FileMode.OpenOrCreate);

                        range.Load(fStream, System.Windows.DataFormats.Rtf);

                        fStream.Close();

                        archivo = dlg.FileName;

                    }

             }
        }
Ejemplo n.º 12
0
        private static void OnBoundDocumentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RichTextBox box = d as RichTextBox;

            if (box == null)
                return;

            RemoveEventHandler(box);

            string newXAML = e.NewValue as string;

            box.Document.Blocks.Clear();
            if (!string.IsNullOrEmpty(newXAML))
            {
                TextRange tr = new TextRange(box.Document.ContentStart, box.Document.ContentEnd);
                MemoryStream ms = new MemoryStream();
                StreamWriter sw = new StreamWriter(ms);
                sw.Write(newXAML);
                sw.Flush();
                tr.Load(ms, DataFormats.Rtf);
                sw.Close();
                ms.Close();
            }


            AttachEventHandler(box);

        }
Ejemplo n.º 13
0
        public void SetText(FlowDocument document, string text) {
            var newText = ChatToXamlConverter.Convert(text);

            var tr = new TextRange(document.ContentStart, document.ContentEnd);
            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(newText)))
                tr.Load(ms, DataFormats.Xaml);
        }
Ejemplo n.º 14
0
        private void RichTextBox_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] docPath = (string[])e.Data.GetData(DataFormats.FileDrop);

                // By default, open as Rich Text (RTF).
                var dataFormat = DataFormats.Rtf;

                // If the Shift key is pressed, open as plain text.
                if (e.KeyStates == DragDropKeyStates.ShiftKey)
                {
                    dataFormat = DataFormats.Text;
                }

                System.Windows.Documents.TextRange range;
                System.IO.FileStream fStream;
                if (System.IO.File.Exists(docPath[0]))
                {
                    try
                    {
                        // Open the document in the RichTextBox.
                        range   = new System.Windows.Documents.TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
                        fStream = new System.IO.FileStream(docPath[0], System.IO.FileMode.OpenOrCreate);
                        range.Load(fStream, dataFormat);
                        fStream.Close();
                    }
                    catch (System.Exception)
                    {
                        MessageBox.Show("File could not be opened. Make sure the file is a text file.");
                    }
                }
            }
        }
Ejemplo n.º 15
0
        public void LoadData()
        {
            string Narr;
            string NarrFormat;

            if (mIsSummaryNarrative)
            {
                Narr = mDataSet.Tables["i9Narrative"].Rows[0]["SummaryNarrative"].ToString();
                NarrFormat = mDataSet.Tables["i9Narrative"].Rows[0]["SummaryNarrativeFormat"].ToString();
            }
            else
            {
                Narr = mDataSet.Tables["i9Narrative"].Rows[0]["Narrative"].ToString();
                NarrFormat = mDataSet.Tables["i9Narrative"].Rows[0]["NarrativeFormat"].ToString();
            }

            if (String.IsNullOrEmpty(NarrFormat.Trim()) == false)
            {
                // convert string to stream
                byte[] byteArray = Encoding.ASCII.GetBytes(NarrFormat);
                using (MemoryStream stream = new MemoryStream(byteArray))
                {
                    TextRange range = new TextRange(mainRTB.Document.ContentStart, mainRTB.Document.ContentEnd);
                    range.Load(stream, DataFormats.Rtf);
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 获取文档分页器
        /// </summary>
        /// <param name="pageWidth"></param>
        /// <param name="pageHeight"></param>
        /// <returns></returns>
        public DocumentPaginator GetPaginator(double pageWidth,double pageHeight)
        {
            //将RichTextBox的文档内容转为XAML
            TextRange originalRange = new TextRange(
            _textBox.Document.ContentStart,
            _textBox.Document.ContentEnd
            );
            MemoryStream memoryStream = new MemoryStream();
            originalRange.Save(memoryStream, System.Windows.DataFormats.XamlPackage);

            //根据XAML将流文档复制一份
            FlowDocument copy = new FlowDocument();

            TextRange copyRange = new TextRange(
            copy.ContentStart,
            copy.ContentEnd
            );
            copyRange.Load(memoryStream, System.Windows.DataFormats.XamlPackage);

            DocumentPaginator paginator =
            ((IDocumentPaginatorSource)copy).DocumentPaginator;

            //转换为新的分页器
            return new PrintingPaginator(
            paginator,new Size( pageWidth,pageHeight),
            new Size(DPI,DPI)
            );
        }
Ejemplo n.º 17
0
        private void MyRichTextBox_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] docPath = (string[])e.Data.GetData(DataFormats.FileDrop);

                // По умолчанию открыть как форматированный текст
                var dataFormat = DataFormats.Rtf;

                // Если нажата клавиша Shift, открыть как обычный текст.
                if (e.KeyStates == DragDropKeyStates.ShiftKey)
                {
                    dataFormat = DataFormats.Text;
                }

                System.Windows.Documents.TextRange range;
                System.IO.FileStream fStream;
                if (System.IO.File.Exists(docPath[0]))
                {
                    try
                    {
                        // Откройте документ в RichTextBox.
                        range   = new System.Windows.Documents.TextRange(MyRichTextBox.Document.ContentStart, MyRichTextBox.Document.ContentEnd);
                        fStream = new System.IO.FileStream(docPath[0], System.IO.FileMode.OpenOrCreate);
                        range.Load(fStream, dataFormat);
                        fStream.Close();
                    }
                    catch (System.Exception)
                    {
                        MessageBox.Show("File could not be opened. Make sure the file is a text file.");
                    }
                }
            }
        }
        private void LoadCompleted(object sender, RoutedEventArgs e)
        {
            string codeBase = Assembly.GetExecutingAssembly().CodeBase;
            UriBuilder uri = new UriBuilder(codeBase);
            string path = Uri.UnescapeDataString(uri.Path);
            if (!string.IsNullOrEmpty(path))
            {
                var legalReleasePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(path), "legal_release.txt");

                try
                {
                    if (File.Exists(legalReleasePath))
                    {
                        var textRange = new TextRange(RtfContainer.Document.ContentStart,
                            RtfContainer.Document.ContentEnd);
                        using (var fileStream = new FileStream(legalReleasePath, FileMode.Open, FileAccess.Read))
                        {
                            textRange.Load(fileStream, DataFormats.Text);
                        }
                    }
                    else
                        throw new FileNotFoundException("legal_release.txt");
                }
                catch (Exception ex)
                {
                    ServiceManager.LogError("Load Legal release", ex);
                }
            }
        }
Ejemplo n.º 19
0
        private void open_button_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            openFileDialog1.Filter = @"Evennote File(*.note)|*.note";

            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == true)
            {
                Note temp = Evennote.OpenNoteFromFile(openFileDialog1.FileName);

                titleTextBox.Text = temp.Title;

                using (MemoryStream mem = new MemoryStream())
                {
                    TextRange range = new TextRange(temp.Text.ContentStart,
                        temp.Text.ContentEnd);
                    range.Save(mem, DataFormats.XamlPackage);
                    mem.Position = 0;

                    TextRange kange = new TextRange(richTextBox.Document.ContentStart,
                        richTextBox.Document.ContentEnd);
                    kange.Load(mem, DataFormats.XamlPackage);
                }
            }
        }
Ejemplo n.º 20
0
        private void Credits_Click(object sender, RoutedEventArgs e)
        {
            this.Mainwindow.BackGrid.Children.Clear();
            this.Mainwindow.MainGrid.Visibility = Visibility.Hidden;
            creditCanvas.Background = Brushes.White;
            creditCanvas.IsHitTestVisible = true;
            RichTextBox richTextBox1 = new RichTextBox();
            creditCanvas.Children.Add(richTextBox1);
            FileStream fs = new FileStream("Documents\\Credits\\credits.rtf", FileMode.Open, FileAccess.Read);

            TextRange RTBText = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd);
            RTBText.Load(fs, DataFormats.Rtf);
            richTextBox1.Width = 1920;
            richTextBox1.Height = 10000;
            richTextBox1.HorizontalAlignment = HorizontalAlignment.Center;
            richTextBox1.Background = Brushes.Black;
            richTextBox1.Foreground = Brushes.WhiteSmoke;
            richTextBox1.FontFamily = new FontFamily("Segoe UI");

            richTextBox1.BorderThickness = new Thickness(0);
            TranslateTransform ttransform = new TranslateTransform();
            richTextBox1.RenderTransform= ttransform;
            DoubleAnimation scrollAnim = new DoubleAnimation(0,-10000,new Duration(TimeSpan.FromSeconds(60)),FillBehavior.Stop);
            scrollAnim.Completed += new EventHandler(scrollAnim_Completed);
            richTextBox1.ClipToBounds = true;
            //scrollAnim.RepeatBehavior = RepeatBehavior.Forever;
            ttransform.BeginAnimation(TranslateTransform.YProperty, scrollAnim);
            creditCanvas.PreviewMouseDown += new MouseButtonEventHandler(creditCanvas_PreviewMouseDown);
            this.Mainwindow.BackGrid.Children.Add(creditCanvas);
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Загрузка текста в окно помощи из файла
 /// </summary>
 public HelpWindow()
 {
     InitializeComponent();
     MainWindow.HelpWindow = this;
     TextRange helpDoc = new TextRange(Helper.Document.ContentStart, Helper.Document.ContentEnd);
     using (FileStream fs = new FileStream("..\\..\\..\\Help.txt", FileMode.Open))
         helpDoc.Load(fs, "Text");
 }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     var document = new FlowDocument();
     var range = new TextRange(document.ContentStart, document.ContentEnd);
     var stream = GetStream(value); // implement this method to get memorystream from the value which is ur rtf data.
     range.Load(stream, DataFormats.Rtf);
     return document;
 }
Ejemplo n.º 23
0
 public void SetText(FlowDocument document, string text)
 {
     TextRange tr = new TextRange(document.ContentStart, document.ContentEnd);
     using (MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(text)))
     {
         tr.Load(ms, DataFormats.Rtf);
     }
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Creates a flow document from the <paramref name="content"/>
        /// </summary>
        /// <param name="content">The content of the stream to be added to the <see cref="FlowDocument"/></param>
        /// <returns>A <see cref="FlowDocument"/></returns>
        public static FlowDocument CreateFlowDocument(Stream content)
        {
            FlowDocument fd = new FlowDocument();
            TextRange textRange = new TextRange(fd.ContentStart, fd.ContentEnd);
            textRange.Load(content, DataFormats.Rtf);

            return fd;
        }
Ejemplo n.º 25
0
        private void LoadNotes()
        {
            if(string.IsNullOrEmpty(Trade.Notes)) return;

            TextRange tr = new TextRange(NotesTextBox.Document.ContentStart, NotesTextBox.Document.ContentEnd);
            //convert string to MemoryStream 
            MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(Trade.Notes));
            tr.Load(ms, DataFormats.Rtf); 
        }
Ejemplo n.º 26
0
        private static void LoadRtfToRange(string rtf, TextRange range)
        {
            if (rtf.IsBlank()) return;

            var byts = Encoding.UTF8.GetBytes(rtf);

            if (byts.Length != 0)
                range.Load(new MemoryStream(byts), DataFormats.Rtf);
        }
Ejemplo n.º 27
0
 public void OnFragmentNavigation(FragmentNavigationEventArgs e)
 {
     int id = int.Parse(e.Fragment);
     Entity.Contest contest = App.Server.GetContest(id);
     var wholeRange = new TextRange(txtDescription.Document.ContentStart, txtDescription.Document.ContentEnd);
     using (MemoryStream mem = new MemoryStream(Encoding.UTF8.GetBytes(contest.Description)))
     {
         wholeRange.Load(mem, DataFormats.Rtf);
     }
 }
Ejemplo n.º 28
0
 public static FlowDocument XamlToFlowDocument(string text)
 {
     var document = new FlowDocument();
     using (var stream = new MemoryStream((new UTF8Encoding()).GetBytes(text)))
     {
         var txt = new TextRange(document.ContentStart, document.ContentEnd);
         txt.Load(stream, DataFormats.Xaml);
     }
     return document;
 }
Ejemplo n.º 29
0
 private void LoadTerms()
 {
     TextRange textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
     var assembly = typeof(TermsDialog).Assembly;
     var resourceName = "Sdl.Community.BetaAPIs.UI.Resources.SDL OpenExchange Terms and Conditions.rtf";
     using (var stream = assembly.GetManifestResourceStream(resourceName))
    // using (var streamReader = new StreamReader(stream))
     {
         textRange.Load(stream, DataFormats.Rtf);
     }
 }
Ejemplo n.º 30
0
        private static void ReadFile(string inFilename, FlowDocument inFlowDocument)
        {
            if (System.IO.File.Exists(inFilename))
            {
                TextRange range = new TextRange(inFlowDocument.ContentStart, inFlowDocument.ContentEnd);
                FileStream fStream = new FileStream(inFilename, FileMode.Open, FileAccess.Read, FileShare.Read);

                range.Load(fStream, DataFormats.Rtf);
                fStream.Close();
            }
        }
Ejemplo n.º 31
0
        private static void LoadAboutContent(FlowDocument doc)
        {
            var assembly = System.Reflection.Assembly.GetExecutingAssembly();
            var resourceName = "MiningController.AboutContent.rtf";

            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
            {
                var range = new TextRange(doc.ContentStart, doc.ContentEnd);
                range.Load(stream, DataFormats.Rtf);
            }
        }
Ejemplo n.º 32
0
 public void OnFragmentNavigation(FragmentNavigationEventArgs e)
 {
     problemID = int.Parse(e.Fragment);
     var problem = App.Server.GetProblem(problemID);
     txtTitle.Text = problem.Title;
     var wholePage = new TextRange(txtContent.Document.ContentStart, txtContent.Document.ContentEnd);
     using (MemoryStream mem = new MemoryStream(Encoding.UTF8.GetBytes(problem.Content)))
     {
         wholePage.Load(mem, DataFormats.Rtf);
     }
 }
Ejemplo n.º 33
0
 /// <summary>
 /// There is no easy way to build to an rtf resource
 /// </summary>
 private void LoadInstructions()
 {
     Uri uri = new Uri("pack://application:,,,/Resources/Documents/Help.rtf");
     StreamResourceInfo sri = Application.GetResourceStream(uri);
     if (sri != null)
     {
         TextRange range = new TextRange(
             richTextBox.Document.ContentStart,
             richTextBox.Document.ContentEnd);
         range.Load(sri.Stream, DataFormats.Rtf);
     }
 }
Ejemplo n.º 34
0
        public void RefreshLog()
        {
            // Formateamos la salida de HTML a XAML
            FlowDocument document = txtLogger.Document;
            String text = HtmlToXamlConverter.ConvertHtmlToXaml(App.Registry, false);

            var tr = new TextRange(document.ContentStart, document.ContentEnd);
            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(text)))
            {
                tr.Load(ms, DataFormats.Xaml);
            }
        }
Ejemplo n.º 35
0
        private void DocBox_Drop(object sender, DragEventArgs e)
        {
            MainWindow win = new MainWindow();

            win.Show();
            string[] docPath = (string[])e.Data.GetData(DataFormats.FileDrop);

            TextRange range = new System.Windows.Documents.TextRange(win.DocBox.Document.ContentStart, win.DocBox.Document.ContentEnd);

            FileStream fStream = new System.IO.FileStream(docPath[0], System.IO.FileMode.OpenOrCreate);

            range.Load(fStream, DataFormats.Text);

            path.Add(docPath[0]);
            AddLastFiles();
            ReadLastFiles();

            fStream.Close();
            win.Title = docPath[0];
        }
Ejemplo n.º 36
0
        private static string ConvertRtfToXaml(string rtfText)
        {
            var richTextBox = new RichTextBox();

            if (string.IsNullOrEmpty(rtfText))
            {
                return("");
            }

            var textRange = new System.Windows.Documents.TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);

            //Create a MemoryStream of the Rtf content

            using (var rtfMemoryStream = new MemoryStream())
            {
                using (var rtfStreamWriter = new StreamWriter(rtfMemoryStream))
                {
                    rtfStreamWriter.Write(rtfText);
                    rtfStreamWriter.Flush();
                    rtfMemoryStream.Seek(0, SeekOrigin.Begin);

                    //Load the MemoryStream into TextRange ranging from start to end of RichTextBox.
                    textRange.Load(rtfMemoryStream, DataFormats.Rtf);
                }
            }

            using (var rtfMemoryStream = new MemoryStream())
            {
                textRange = new System.Windows.Documents.TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
                textRange.Save(rtfMemoryStream, DataFormats.Xaml);
                rtfMemoryStream.Seek(0, SeekOrigin.Begin);
                using (var rtfStreamReader = new StreamReader(rtfMemoryStream))
                {
                    return(rtfStreamReader.ReadToEnd());
                }
            }
        }