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 且繫結至自訂 XML 組件中之項目的 PlainTextContentControl。 如需示範如何將內容控制項繫結至自訂 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 組件