开发者

Binding CustomXml to Headerpart

开发者 https://www.devze.com 2022-12-21 15:04 出处:网络
I am at my whits-end with this problem. I can successful bind xml to the main document part, however I cannot seem to be able to get content controls in the header to bind to the xml.

I am at my whits-end with this problem. I can successful bind xml to the main document part, however I cannot seem to be able to get content controls in the header to bind to the xml.

AddCustomXmlPart doesn't seem to exist for Headerpart an开发者_如何转开发d if I try to add a CustomXmlPart via hdrpart.AddPart(xmlPart);

I get an Invalid operation exception "The part cannot be added here" and cannot use hdrpart.AddNewPart(); as CustomXmlPart isn't an IFixedContentTypePart.

I have spent the last few days searching for examples on how to bind data to the header but all to no avail. There are plenty of examples on creating new headers, moving headers etc, but nothing on binding CustomXml to the header.

I hope someone can shed some light on this.

Thanks in advance.

Al


take a look at the implementation using reflector. There you can see that the MainDocumentPart defines some Constraints regarding the parts that can be added. These definitions are made in the GetPartConstraint() method (This method is derived from the OpenXmlPartContainer).

The GetPartConstraints() method of the MainDocumentPart defines that CustomXmlPart is allowed. The GetPartConstraints() method of the HeaderPart does not defines that CustomXmlPart is allowed. --> That is the reason for the Exception.

I hope that answers your question.

Regards.

0

精彩评论

暂无评论...
验证码 换一张
取 消