ContentControlStoreUpdatingEventArgs.Content 属性

获取正在保存至绑定到内容控件的自定义 XML 部件中的文本。

命名空间:  Microsoft.Office.Tools.Word
程序集:  Microsoft.Office.Tools.Word(在 Microsoft.Office.Tools.Word.dll 中)

语法

声明
Property Content As String
    Get
    Set
string Content { get; set; }

属性值

类型:System.String
正在保存至绑定到内容控件的自定义 XML 部件中的文本。

备注

可将内容控件绑定到嵌入文档中的某段 XML(也称为“自定义 XML 部件”)内的某个元素。 使用 Content 属性可在 Microsoft Office Word 更新绑定到控件的自定义 XML 部件之前更改文本。

有关更多信息,请参见内容控件自定义 XML 部件概述

示例

下面的代码示例演示 StoreUpdatingContentUpdating 事件的事件处理程序。 此示例假定文档中包含一个名为 plainTextContentControl1 的 PlainTextContentControl,且该控件绑定到某个自定义 XML 部件中的元素。 有关演示如何将内容控件绑定到自定义 XML 部件中的元素的代码示例,请参见演练:将内容控件绑定到自定义 XML 部件

若要使用此代码,请将其粘贴到项目内的 ThisDocument 类中。 对于 C#,还必须将这两个事件处理程序附加到 plainTextContentControl1 的 StoreUpdatingContentUpdating 事件。

此示例针对的是文档级自定义项。

Private Sub plainTextContentControl1_StoreUpdating(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.ContentControlStoreUpdatingEventArgs) _
    Handles PlainTextContentControl1.StoreUpdating

    MessageBox.Show("The control was changed to the following value: " & vbCrLf & _
        e.Content & vbCrLf & "This value is about to be written to the node that is bound to this control.")
End Sub

Private Sub plainTextContentControl1_ContentUpdating(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.ContentControlContentUpdatingEventArgs) _
    Handles PlainTextContentControl1.ContentUpdating

    MessageBox.Show("The node that is bound to this control was changed to the following value: " & vbCrLf & _
        e.Content & vbCrLf & "This value is about to be written to this control.")
End Sub
void plainTextContentControl1_StoreUpdating(object sender, 
    Microsoft.Office.Tools.Word.ContentControlStoreUpdatingEventArgs e)
{
    MessageBox.Show("The control was changed to the following value: \n\n" +
        e.Content + "\n\nThis value is about to be written to the node that is bound to this control.");
}

void plainTextContentControl1_ContentUpdating(object sender, 
    Microsoft.Office.Tools.Word.ContentControlContentUpdatingEventArgs e)
{
    MessageBox.Show("The node that is bound to this control was changed to the following value: \n\n" +
        e.Content + "\n\nThis value is about to be written to this control.");
}

.NET Framework 安全性

请参见

参考

ContentControlStoreUpdatingEventArgs 接口

Microsoft.Office.Tools.Word 命名空间

其他资源

内容控件

自定义 XML 部件概述

演练:将内容控件绑定到自定义 XML 部件