ContentControlContentUpdatingEventArgs.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 組件概觀

範例

下列程式碼範例會示範 ContentUpdatingStoreUpdating 事件的事件處理常式。 這個範例假設文件中包含名為 plainTextContentControl1 且繫結至自訂 XML 組件中之項目的 PlainTextContentControl。 如需示範如何將內容控制項繫結至自訂 XML 組件中項目的程式碼範例,請參閱逐步解說:將內容控制項繫結至自訂 XML 組件

若要使用這段程式碼,請將它貼到專案的 ThisDocument 類別中。 若為 C#,您還必須將事件處理常式附加至 plainTextContentControl1 的 ContentUpdatingStoreUpdating 事件。

這是示範文件層級自訂的範例。 您可以修改這個範例,使其可透過應用程式層級增益集執行。 如需詳細資訊,請參閱在應用程式層級增益集的執行階段中擴充 Word 文件和 Excel 活頁簿

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

請參閱

參考

ContentControlContentUpdatingEventArgs 介面

Microsoft.Office.Tools.Word 命名空間

其他資源

內容控制項

自訂 XML 組件概觀

逐步解說:將內容控制項繫結至自訂 XML 組件