RadExpressionEditor: How to match multi-line text

1 Answer 22 Views
ExpressionEditor
Stephen
Top achievements
Rank 1
Stephen asked on 16 Dec 2024, 04:36 PM | edited on 16 Dec 2024, 06:31 PM

When a string field contains multiple lines, what is the correct text to put into the editor to match that multi-line field?

I've modified the Telerik sample, https://docs.telerik.com/devtools/wpf/controls/radexpressioneditor/getting-started, so that the Occupation for Sarah Blake contains a newline between Supplied and Manager. How does a user match the occupation? What is the correct escape sequence? Two double quotes, "", works for matching an embedded double quote, ",  but how does one match embedded newlines?

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 19 Dec 2024, 12:44 PM

Hello Stephen,

The ExpressionEditor doesn't support the new line character ('\n'). The '\' symbol will be escaped and in the end you will get the "Supplied\\nManager" as string token in the expression.

To add a new line, you can implement a custom function and use it in the editor.

 public class CustomExpressionFunctionContext : ExpressionFunctionContext
 {
     [Description("Add new line")]
     public char NewLine()
     {
         return '\n';
     }
 }

 public class CustomExpressionEditorViewModel : ExpressionEditorViewModel
 {
     protected override IEnumerable<EditorModelBase> GetFunctionsItemModels()
     {
         List<EditorModelBase> list = new List<EditorModelBase>(base.GetFunctionsItemModels());

         var other = list.First(x => x.Name == "Other") as EditorCategoryModel;            
         other.Children.Add(new FunctionEditorItemModel(typeof(CustomExpressionFunctionContext).GetMethod(nameof(CustomExpressionFunctionContext.NewLine), BindingFlags.Public | BindingFlags.Instance), other.Name));

         return list;
     }
 }


 public MainWindow()
 {
     InitializeComponent();
     ExpressionFunctionContext.Context = new CustomExpressionFunctionContext();
     this.ExpressionEditor.ViewModel = new CustomExpressionEditorViewModel();
 }


I hope this helps.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
ExpressionEditor
Asked by
Stephen
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or