I comprehend MVVM with MVVM Light and I have a problem with the RichTextBox. I zabindil its Text property and it turns out to change it from ViewModel, but when I need to access the rows that the user typed in the RichTextBox in ViewModel, I constantly get null. How to fix it? I don’t know if it matters, but just in case I’ll clarify that I still use MahApps.Metro.

<RichTextBox x:Name="RichTextBoxOther" HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"> <FlowDocument PageWidth="1000"> <Paragraph> <Run Text="{Binding RichTextBoxOther_Text, Mode=TwoWay}" /> </Paragraph> </FlowDocument> </RichTextBox> 
  private string _richTextBoxOther_Text; public string RichTextBoxOther_Text { get { return _richTextBoxOther_Text; } set { _richTextBoxOther_Text = value; RaisePropertyChanged(() => RichTextBoxOther_Text); } } 

    1 answer 1

    In short, no way. New Paragraph and Inline 's can be added to the control as you type.

    RichTextBox does not expose properties that can be bind. (You can only bind text that you create and do not allow the user to edit.) But it contains the Document property, which refers to FlowDocument , which is essentially a VM for RichTextBox 'a.

    Therefore, if you want to apply the MVVM approach, bring out the FlowDocument in the VM and operate it there.