如何动态地将数据与富文本框的文档属性绑定.我在使用c#的Wpf中使用MVVM?
编辑:
我在"codeproject.com/KB/WPF/BindableWPFRichTextBox.aspx"中尝试了这个例子; 但我无法理解那个例子中发生了什么.我是WPF和MVVM的新手.
它在线上抛出错误
try {
var stream = new MemoryStream(Encoding.UTF8.GetBytes(GetDocumentXaml(richTextBox)));
var doc = (FlowDocument)XamlReader.Load(stream);
// Set the document
richTextBox.Document = doc;
}
catch (Exception) { richTextBox.Document = new FlowDocument(); }
Run Code Online (Sandbox Code Playgroud)
错误类似于"根级别的数据无效.第1行,位置1".我给的价值就像"样本文本"
我发现xaml文本应该是这样的
<FlowDocument PagePadding="5,0,5,0" AllowDrop="True" xmlns="schemas.microsoft.com/winfx/2006/xaml/… generated by app back-end</Paragraph>
</FlowDocument>" But how to get this text?
Run Code Online (Sandbox Code Playgroud) 您好,我正在使用 WPF 并使用 MVVM 模式。所以我的问题是,我试图将 RichTextBox 的选定文本绑定到 ViewModel 中的属性,但无法绑定 Selection 属性。
那么我该怎么做呢?
我认为将 RichTextBox 的 Selection 属性绑定到 ViewModel 中的属性是更好地将效果和装饰应用于文本的方法。
如果有人知道更好的方法来了解 ViewModel 中 RichTextBox 的选定文本,请告诉我。我开始学习 FlowDocuments 并使用 RichTextBox,所以这就是我有点迷失的原因。
提前致谢!
对于某些人来说,这可能是一个非常基本的问题,但我很困难,并且无法从堆栈或谷歌找到直接答案.如果有人可以帮助那将是伟大的,我想知道如何将RichTextbox绑定Text到字符串.
所以我的MVVM上有一个名为Notes的变量,并希望将它绑定到Radrichtextbox.
我正在考虑这个问题:
<RichTextBox x:Name="RichTextBox1" Text="{Binding Notes}" />
Run Code Online (Sandbox Code Playgroud)
但是没有文字方法:S