-
Notifications
You must be signed in to change notification settings - Fork 0
/
DocumentPropertiesActions.cs
76 lines (68 loc) · 3.59 KB
/
DocumentPropertiesActions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.Xpf.RichEdit;
namespace DXRichEditControlAPISample.CodeExamples
{
class DocumentPropertiesActions
{
static void StandardDocumentProperties(Document document)
{
#region #StandardDocumentProperties
document.BeginUpdate();
document.DocumentProperties.Creator = "John Doe";
document.DocumentProperties.Title = "Inserting Custom Properties";
document.DocumentProperties.Category = "TestDoc";
document.DocumentProperties.Description = "This code demonstrates API to modify and display standard document properties.";
document.Fields.Create(document.AppendText("\nAUTHOR: ").End, "AUTHOR");
document.Fields.Create(document.AppendText("\nTITLE: ").End, "TITLE");
document.Fields.Create(document.AppendText("\nCOMMENTS: ").End, "COMMENTS");
document.Fields.Create(document.AppendText("\nCREATEDATE: ").End, "CREATEDATE");
document.Fields.Create(document.AppendText("\nCategory: ").End, "DOCPROPERTY Category");
document.Fields.Update();
document.EndUpdate();
#endregion #StandardDocumentProperties
}
static void CustomDocumentProperties(Document document)
{
#region #CustomDocumentProperties
document.BeginUpdate();
document.AppendText("A new value of MyBookmarkProperty is obtained from here: NEWVALUE!\n");
document.Bookmarks.Create(document.FindAll("NEWVALUE!", SearchOptions.CaseSensitive)[0], "bmOne");
document.AppendText("\nMyNumericProperty: ");
document.Fields.Create(document.Range.End, "DOCVARIABLE CustomProperty MyNumericProperty");
document.AppendText("\nMyStringProperty: ");
document.Fields.Create(document.Range.End, "DOCVARIABLE CustomProperty MyStringProperty");
document.AppendText("\nMyBooleanProperty: ");
document.Fields.Create(document.Range.End, "DOCVARIABLE CustomProperty MyBooleanProperty");
document.AppendText("\nMyBookmarkProperty: ");
document.Fields.Create(document.Range.End, "DOCVARIABLE CustomProperty MyBookmarkProperty");
document.EndUpdate();
document.CustomProperties["MyNumericProperty"] = 123.45;
document.CustomProperties["MyStringProperty"] = "The Final Answer";
document.CustomProperties["MyBookmarkProperty"] = document.Bookmarks[0];
document.CustomProperties["MyBooleanProperty"] = true;
document.CalculateDocumentVariable += DocumentPropertyDisplayHelper.OnCalculateDocumentVariable;
document.Fields.Update();
#endregion #CustomDocumentProperties
}
#region #@CustomDocumentProperties
class DocumentPropertyDisplayHelper
{
public static void OnCalculateDocumentVariable(object sender, DevExpress.XtraRichEdit.CalculateDocumentVariableEventArgs e)
{
if (e.Arguments.Count == 0 || e.VariableName != "CustomProperty")
return;
string name = e.Arguments[0].Value;
var customProperty = ((DevExpress.Xpf.RichEdit.RichEditControl)sender).Document.CustomProperties[name];
if (customProperty != null)
e.Value = customProperty.ToString();
e.Handled = true;
}
}
#endregion #@CustomDocumentProperties
}
}