ContentControlBase.ContentUpdating 事件

如果内容控件绑定到自定义 XML 部件,则此事件在 Microsoft Office Word 更新内容控件中的文本之前发生。

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

语法

声明
Event ContentUpdating As ContentControlContentUpdatingEventHandler
event ContentControlContentUpdatingEventHandler ContentUpdating

备注

可将内容控件绑定到嵌入文档中的某段 XML(也称为“自定义 XML 部件”)内的某个元素。有关更多信息,请参见内容控件自定义 XML 部件概述

只有在文档打开的状态下,修改自定义 XML 部件中的数据时,才会引发 ContentUpdating 事件。在打开文档时,以及在文档关闭的状态下修改自定义 XML 部件中的数据时,都不会引发此事件。

有关处理事件的更多信息,请参见使用事件

示例

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

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

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

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 安全性

请参见

参考

ContentControlBase 接口

Microsoft.Office.Tools.Word 命名空间

其他资源

内容控件

自定义 XML 部件概述

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