Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否重置WPF flowdocument元素名称?_Wpf_Flowdocument - Fatal编程技术网

是否重置WPF flowdocument元素名称?

是否重置WPF flowdocument元素名称?,wpf,flowdocument,Wpf,Flowdocument,我有一个名为Span test1的flowdocument,我想用编程的方式替换它的内容 TextRange tr = new TextRange(this.test1.ContentStart,this.test1.ContentEnd); Run run = this.test1.Inlines.First() as Run; run.Text = "replaced text"; 这是可行的,但是问题是在执行更新时,从xaml源中删除了范围的名称。这是故意的吗?有没有办法保留身份证的密

我有一个名为Span test1的flowdocument,我想用编程的方式替换它的内容

TextRange tr = new TextRange(this.test1.ContentStart,this.test1.ContentEnd);
Run run = this.test1.Inlines.First() as Run;

run.Text = "replaced text";
这是可行的,但是问题是在执行更新时,从xaml源中删除了范围的名称。这是故意的吗?有没有办法保留身份证的密码? 您好,这是我用来调试richtextbox设置xaml source为textbox的实际内容的方法

使用MemoryStream ms=新MemoryStream { tr=新文本范围this.richTextBox1.Document.ContentStart,this.richTextBox1.Document.ContentEnd; tr.Savems,DataFormats.Xaml; ms.Position=0

            using (StreamReader sr = new StreamReader(ms))
            {
                this.textBox1.Text = sr.ReadToEnd();
            }
        }
这是richtextbox的测试内容:

<FlowDocument>
        <Paragraph>
            This is my first  <Span Name="test1">a huge amount of space</Span> between it and the second paragraph?
        </Paragraph>
    </FlowDocument>

不幸的是,这正是FlowDocuments处理标记的方式。我找到的唯一一个非常棘手的解决方案是在FontFamily属性中隐藏一个名称。这是有效的,因为该属性是一个逗号分隔的字符串列表,第一个与现有字体系列匹配的字符串正在使用,其余的被忽略。如果你可以这样做:

document.FontFamily = "RealFont1, RealFont2, name=test1";
整个字符串将被保留。然后,您可以通过在FontFamily中搜索name=,来访问该名称


同样,这是一个非常粗糙的问题,但经过几个月的尝试,这是我能找到的唯一解决方案。

您如何看待xaml源代码?Id是什么意思?您是否也可以用flowdocument发布您的xaml代码?您好,我正在将整个文档的textrange内容保存为DataFormats。xaml是我在文本框中为debu查看的字符串对于Id,我只是指span元素中的Name属性