c# - How to completely clear/set text of WinRT's RichEditBox? -
how 1 overwrite or clear text (and formatting) of winrt's richeditbox?
i'm asking because method settext of it's document property seems append new text.
thus "binding" below:
void vm_propertychanged(object sender, system.componentmodel.propertychangedeventargs e) { if (e.propertyname == "content") richeditbox.document.settext(windows.ui.text.textsetoptions.none, vm.content); } private void contentchanged(object sender, routedeventargs e) { richeditbox box = (richeditbox)sender; string content; box.document.gettext(windows.ui.text.textgetoptions.none, out content); vm.content = content; }
where vm_propertychanged
listens changes in content
string property of viewmodel , contentchanged
handler textchanged
event of richeditbox, create infinite loop appending "\r" vm.content , box's text itself. when replace textgetoptions.none
textgetoptions.formatrtf
viewmodel's content
property gets more messy adding looks empty rtf paragraphs.
here's content property definition in viewmodel can ensure everything's ok it:
/// <summary> /// <see cref="content" /> property's name. /// </summary> public const string contentpropertyname = "content"; private string _content; /// <summary> /// sets , gets content property. /// changes property's value raise propertychanged event. /// </summary> public string content { { return _content; } set { if (_content == value) { return; } raisepropertychanging(contentpropertyname); _content = value; raisepropertychanged(contentpropertyname); } }
edit:
some experiments:
richeditbox.document.settext(windows.ui.text.textsetoptions.none, string.empty); string content; richeditbox.document.gettext(windows.ui.text.textgetoptions.none, out content); //content became "\r" richeditbox.document.settext(windows.ui.text.textsetoptions.none, content); richeditbox.document.gettext(windows.ui.text.textgetoptions.none, out content); //content became "\r\r"
edit:
another experiment:
a simple workaround textgetoptions.none
trimming "\r" on output. textgetoptions.formatrtf
things aren't simple:
richeditbox box = new richeditbox(); box.document.settext(windows.ui.text.textsetoptions.formatrtf, string.empty); string content; box.document.gettext(windows.ui.text.textgetoptions.formatrtf, out content); //content // {\\rtf1\\fbidis\\ansi\\ansicpg1250\\deff0\\nouicompat\\deflang1045{\\fonttbl{\\f0\\fnil segoe ui;}}\r\n{\\colortbl ;\\red255\\green255\\blue255;}\r\n{\\*\\generator riched20 6.2.9200}\\viewkind4\\uc1 \r\n\\pard\\ltrpar\\tx720\\cf1\\f0\\fs17\\lang1033\\par\r\n}\r\n\0 box.document.settext(windows.ui.text.textsetoptions.formatrtf, content); box.document.gettext(windows.ui.text.textgetoptions.formatrtf, out content); //and it's // {\\rtf1\\fbidis\\ansi\\ansicpg1250\\deff0\\nouicompat\\deflang1045{\\fonttbl{\\f0\\fnil segoe ui;}{\\f1\\fnil segoe ui;}}\r\n{\\colortbl ;\\red255\\green255\\blue255;}\r\n{\\*\\generator riched20 6.2.9200}\\viewkind4\\uc1 \r\n\\pard\\ltrpar\\tx720\\cf1\\f0\\fs17\\lang1033\\par\r\n\r\n\\pard\\ltrpar\\tx720\\f1\\fs17\\par\r\n}\r\n\0
i apologize english. corrections concerning welcome :)
the /r (or \par if query rtf) appears bug in richeditbox. can worked around however, doing this:
string temp; // not ask rtf here, want raw text richeditbox.document.gettext(textgetoptions.none, out temp); var range = richeditbox.document.getrange(0, temp.length - 1); string content; // ask rtf here, if desired. range.gettext(textgetoptions.formatrtf, out content);
Comments
Post a Comment