|
Using System;
Using System.Collections.Generic;
Using System.IO;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Windows;
Using System.Windows.Controls;
Using System.Windows.Data;
Using System.Windows.Documents;
Using System.Windows.Input;
Using System.Windows.Media;
Using System.Windows.Media.Imaging;
Using System.Windows.Navigation;
Using System.Windows.Shapes;
Namespace Kaitone.DetectiveHelper.UI.Controls.RichTextBox
{
<summary>
The interactive logic of Richboxtextshow.xaml
</summary>
public partial class Richboxtextshow:usercontrol
{
public static readonly DependencyProperty Textyproperty =
Dependencyproperty.register ("Text", typeof (String),
typeof (Richboxtextshow), new PropertyMetadata (string. Empty,new
Propertychangedcallback (textypropertychanged)
));
private static void Textypropertychanged (DependencyObject Sender,dependencypropertychangedeventargs args)
{
Richboxtextshow editer = new Richboxtextshow ();
}
public string Text
{
get {return converttortfstring (THIS.MAINRTB);}
set {
if (! String.IsNullOrEmpty (value))
{
Loadfromrtfstring (VALUE,THIS.MAINRTB);
}
Else
{
This.mainRTB.Document.Blocks.Clear ();
}
}
}
private static void Loadfromrtfstring (String rtf, System.Windows.Controls.RichTextBox RichTextBox)
{
if (string. IsNullOrEmpty (RTF))
{
throw new ArgumentNullException ();
}
TextRange TextRange = new TextRange (RichTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
using (MemoryStream ms = new MemoryStream ())
{
using (StreamWriter sw = new StreamWriter (ms))
{
Sw. Write (RTF);
Sw. Flush ();
Ms. Seek (0, seekorigin.begin);
Textrange.load (MS, DATAFORMATS.RTF);
}
}
}
private static string converttortfstring (System.Windows.Controls.RichTextBox RCB)
{
String resultstring = String. Empty;
using (MemoryStream stream=new MemoryStream ())
{
TextRange Documenttextrange = new TextRange (RCB. Document.contentstart, RCB. Document.contentend);
string dataformt = Dataformats.rtf;
Documenttextrange.save (stream, DATAFORMT);
Stream. Seek (0, seekorigin.begin);
using (StreamReader reader=new StreamReader (Stream,encoding.default)) {
resultstring = reader. ReadToEnd ();
}
}
return resultstring;
}
Public Richboxtextshow ()
{
InitializeComponent ();
}
}
}
|