2017-06-16 67 views
0

我想檢查並查看富文本框是否超過4000個字符,如果是,則不要添加到RTF。然而我遇到的問題是我似乎無法找到「允許特殊字符」的選項。我允許退格鍵和刪除,但然後theres CTRL命令,移位等爲富文本框設置最大輸入量,但允許其他特殊鍵

private void RichEditControl_OnPreviewKeyDown(object sender, KeyEventArgs e) 
{ 
    var tr = new TextRange(richEditControl.Document.ContentStart, richEditControl.Document.ContentEnd); 

    e.Handled = (tr.Text.Length >= 4000 && !(e.Key == Key.Back || e.Key == Key.Delete)); 
} 

回答

0
private void RichEditControl_OnPreviewKeyDown(object sender, KeyEventArgs e) 
{ 
    var tr = new TextRange(richEditControl.Document.ContentStart, richEditControl.Document.ContentEnd); 

    e.Handled = tr.Text.Length - richEditControl.Selection.Text.Length>= 4000; 
} 
相關問題