我有一个richtextbox,我打算保存到数据库,可以将其加载回同一个richtextbox.我已经将它工作,以便我可以将flowdocument保存为DataFormats.XamlPackage,它可以保存图像,但问题是文本无法搜索.使用DataFormats.Xaml,我当然有文本,但没有图像.图像将由最终用户粘贴,而不是应用程序附带的图像.
我尝试使用XamlWriter将文本转换为XML,然后单独从文档中获取图像并将它们作为二进制文件插入到XML中,但我似乎无法找到将图像转换为二进制文件的方法...
有没有人有关于如何将图像分成二进制,与文本分开的想法?
提前致谢!
GetImageByteArray()就是问题所在.
码:
private void SaveXML()
{
TextRange documentTextRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
FlowDocument flowDocument = richTextBox.Document;
using (StringWriter stringwriter = new StringWriter())
{
using (System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(stringwriter))
{
XamlWriter.Save(flowDocument, writer );
}
testRTF t = new testRTF();
t.RtfText = new byte[0];
t.RtfXML = GetImagesXML(flowDocument);
t.RtfFullText = stringwriter.ToString();
//save t to database
}
richTextBox.Document.Blocks.Clear();
}
private string GetImagesXML(FlowDocument flowDocument)
{
using (StringWriter stringwriter = new StringWriter())
{
using (System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(stringwriter))
{
Type inlineType;
InlineUIContainer …Run Code Online (Sandbox Code Playgroud) 我正在使用C#4.0并创建了一个DependencyObject MyView.
在MyView中,我有两个DependencyProperties,PropA和PropB,两者都是布尔值.
我想要第三个DependencyProperty,PropC,也是一个bool,简单地说,应该总是给我(PropA || PropB).
我需要为richtextbox打开拼写检查,并将语言设置为用户从下拉列表中选择的语言.现在,我只是通过在xaml中构建richtextbox并为xaml语言属性提供语言来测试它.
我读过两个不同的资源,一个说我需要设置语言属性,另一个说我需要设置xml:lang属性.似乎都没有用.我已经尝试为西班牙语设置任何一个"es",我也尝试将两者设置为"es".我也尝试过将法语设为"fr-FR"而没有成功.唯一发生的事情是英语单词没有标记,但其他语言单词标记为拼写错误.
我还读到我需要更改键盘语言.这对我的应用程序来说是一个问题,因为应用程序中的语言需要动态切换,因此让最终用户转到他们的键盘设置只是因为拼写检查将起作用是一个问题.但是,我已经更改了我的键盘设置,拼写检查仍然无法正常工作.这一次它没有标记拼写错误,甚至拼写错误的英语单词.
我错过了什么?
编辑:上面我的参考资料的一些链接 http://msdn.microsoft.com/en-us/library/system.windows.controls.spellcheck(v=VS.100).aspx
http://www.dev102.com/2008/03/25/customize-spellcheck-on-wpf-text-controls/