SetProperty() public method

Used to set a property value and priority within this declaration block
SYNTAX_ERR: Raised if the specified value has a syntax error and is unparsable. NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is readonly or the property is readonly.
public SetProperty ( string propertyName, string value, string priority ) : void
propertyName string The name of the CSS property. See the CSS property index.
value string The new value of the property.
priority string The new priority of the property (e.g. "important").
return void
示例#1
0
        public void TestCssStyleDeclaration()
        {
            rule = (CssStyleRule)cssStyleSheet.CssRules[0];
            CssStyleDeclaration csd = (CssStyleDeclaration)rule.Style;

            Assert.AreEqual("fill:#123456 !important;opacity:0.5;", csd.CssText);
            Assert.AreEqual(2, csd.Length);
            Assert.AreSame(rule, csd.ParentRule);
            Assert.AreEqual("important", csd.GetPropertyPriority("fill"));
            Assert.AreEqual("0.5", csd.GetPropertyValue("opacity"));
            Assert.AreEqual("", csd.GetPropertyPriority("opacity"));
            Assert.AreEqual("#123456", csd.GetPropertyValue("fill"));

            csd.SetProperty("opacity", "0.8", "");
            Assert.AreEqual("0.8", csd.GetPropertyValue("opacity"));
            Assert.AreEqual("", csd.GetPropertyPriority("opacity"));

            csd.SetProperty("opacity", "0.2", "important");
            Assert.AreEqual("0.2", csd.GetPropertyValue("opacity"));
            Assert.AreEqual("important", csd.GetPropertyPriority("opacity"));

            Assert.AreEqual("0.2", csd.RemoveProperty("opacity"));
            Assert.AreEqual(1, csd.Length);

            csd.SetProperty("foo", "bar", "");
            Assert.AreEqual("bar", csd.GetPropertyValue("foo"));
            Assert.AreEqual(2, csd.Length);

            // reset values
            csd.RemoveProperty("foo");
            csd.SetProperty("opacity", "0.5", "");
        }