Pages: 1
Print
Author Topic: Is it possible to update CSS programmatically in C#?  (Read 403 times)
wksim
Member

Posts: 14


« on: August 22, 2011, 12:57:02 PM »

XMetaL version: 6.1
VS: 2010

I have a style defined for an element in the CSS file, and I would like to change the display property to "none" from "inline" and visa versa in C# if possible. Is there a way to do this? I was thinking I may be able to do this using DOMCSSRule object, but I am getting an exception:

  XMetaL.DOMCSSStyleSheet css = cssList.item(i);
  XMetaL.DOMCSSRuleList ruleList = css.cssRules;
  for (int j = 0; j < ruleList.length; j++)
  {
       XMetaL.DOMCSSRule rule = ruleList.item(j);  // --> I am getting an exception here.
       .....
   }

Exception is:

Unable to cast COM object of type 'System.__ComObject' to interface type 'XMetaL.DOMCSSRule'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{2C01DB30-A999-4636-9322-6846ED8B71F5}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 1548



WWW
« Reply #1 on: August 29, 2011, 02:02:50 PM »

There are currently three strategies for modifying CSS that I can think of. Which you use will depend on your needs:

1. Swap the currently loaded CSS file on disk with your modified version (how this is done with any particular language will vary but the easiest way is to have both files in the same folder with different names and then simply rename them so that the CSS file you wish to use matches yourDTDname.css) then call the API Document_object.RefreshCssStyle(). Note that this method will cause the entire document to be reformatted, causing the user's selection to be lost (you may use various strategies to handle that, including inserting a temporary PI to remember the current position, then moving the selection after the API call, then removing the PI at the end).

2. Use new APIs available in the 6.0 releases. See my post here: http://forums.xmetal.com/index.php/topic,594.msg1911.html#msg1911
This is similar to #1 except that it avoids the need to swap files on disk.

3. Set the property Selection.ContainerStyle for a particular node. This will affect one node only (this is different from using a CSS selector that may match one or more nodes in a document, and remains in effect only as long as the document remains open in Tags On or Normal views).
Logged
Pages: 1
Print
Jump to:  

email us