I implemented a custom command like MSWord change case:
It perfectly change case but after executing the selection layout did not upddate.(especially Upper Case All,characters overlays each other).
How to force update layout for selection?
It perfectly change case but after executing the selection layout did not upddate.(especially Upper Case All,characters overlays each other).
How to force update layout for selection?
using
Microsoft.VisualBasic;
using
System;
using
System.Collections;
using
System.Collections.Generic;
using
System.Data;
using
System.Diagnostics;
using
Telerik.Windows.Documents.Commands;
namespace
Commands
{
public
class
ICommandLetterCase : Telerik.Windows.Documents.RichTextBoxCommands.RichTextBoxCommandBase
{
public
ICommandLetterCase(Telerik.Windows.Controls.RadRichTextBox rtb) :
base
(rtb)
{
this
.AssociatedRichTextBox.DocumentChanged += () =>
{
if
((
this
.AssociatedRichTextBox.Document !=
null
)) {
rtb.Document.Selection.SelectionChanged += () => {
base
.OnCanExecuteChanged(); };
}
};
}
protected
override
bool
CanExecuteInReadOnlyMode {
get
{
return
false
; }
}
protected
override
bool
ShouldFocusCaretAfterExecute {
get
{
return
true
; }
}
protected
override
bool
CanExecuteOverride(
object
parameter)
{
if
((
this
.AssociatedRichTextBox !=
null
) &&
this
.AssociatedRichTextBox.Document !=
null
) {
if
(!
this
.AssociatedRichTextBox.Document.Selection.IsEmpty) {
if
(
this
.AssociatedRichTextBox.Document.Selection.GetSelectedBoxes.First
is
Telerik.Windows.Documents.Layout.SpanLayoutBox) {
string
data =
this
.AssociatedRichTextBox.Document.Selection.GetSelectedText();
return
!
string
.IsNullOrEmpty(data) && data.Length > 0;
}
}
}
return
false
;
}
protected
override
void
ExecuteOverride(
object
parameter)
{
try
{
foreach
(Telerik.Windows.Documents.Layout.LayoutBox sbx
in
this
.AssociatedRichTextBox.Document.Selection.GetSelectedBoxes) {
if
(sbx
is
Telerik.Windows.Documents.Layout.SpanLayoutBox) {
if
(!sbx
is
Telerik.Windows.Documents.Layout.FormattingSymbolLayoutBox) {
int
p = Convert.ToInt32(parameter);
dynamic data = ((Telerik.Windows.Documents.Layout.SpanLayoutBox)sbx).Text;
string
newdata = data;
switch
(p) {
case
1:
//all lowercase
newdata = data.ToLower;
break
;
case
2:
//all uppercase
newdata = data.ToUpper;
break
;
case
3:
//first uppercase
System.Text.StringBuilder sb =
new
System.Text.StringBuilder();
sb.Append(data(0).ToString.ToUpper);
for
(i = 1; i <= data.Length - 2; i++) {
if
(data(i + 1) ==
" "
) {
sb.Append(data(i).ToString.ToUpper);
}
else
{
sb.Append(data(i).ToString.ToLower);
}
}
sb.Append(data(data.Length - 1));
newdata = sb.ToString();
break
;
}
var _with1 = (Telerik.Windows.Documents.Layout.SpanLayoutBox)sbx;
_with1.Text = newdata;
}
}
}
}
catch
(Exception ex) {
System.Diagnostics.Debug.Assert(
false
,
"Letter Case ICommand error"
);
}
}
}
}