开发者

Custom RichTextBox and Text Property Binding

I have created a custom RichTextBox control and exposed a Text property. The Text property is defined as follows:

public string Text
{
    get
    {
        return new TextRange(Document.ContentStart, Document.ContentEnd).Text; 
    }
    set
    {
        AppendText(value); 
        OnPropertyChanged("Text");
    }
}

The RichTextBox is using a ViewModel as DataContext as shown below:

<WPF:SharpRichTextBox MaxCharactersAllowed="100" NotificationStyleName="defaultTextBlockStyle"
                      Text="{Binding开发者_JS百科 Path=Name, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
                      DefaultNotificationStyleName="textblockStyle" Margin="10,10,10,10"
                      Background="Yellow">
</WPF:SharpRichTextBox>

Now I want that whenever I change the Text of the RichTextBox the Name property in the ViewModel gets updated. How can I do that?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜