使用CssStyleCollection
內置類。
System.Web.UI.WebControls.Style style = new System.Web.UI.WebControls.Style();
// you can set various properties on style object.
CssStyleCollection cssStyleCollection = style.GetStyleAttributes(SOME_USER_CONTROL OR YOUR PAGE);
cssStyleCollection.Add("border", "1px solid blue"); // etc
另一種選擇是使用以下結構:
List<KeyValuePair<string, List<KeyValuePair<string, string>>> cssValues = new List<KeyValuePair<string, List<KeyValuePair<string, string>>>();
cssValues.Add(new KeyValuePair<string, List<KeyValuePair<string, string>>("abc", new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("border", "1px solid blue"),
new KeyValuePair<string, string>("color", "black"),
// so on
}));
我們使用KeyValuePairs而不是字典的名單,因爲CSS類可以重複並沒有唯一性保證。
請添加一些使用示例。你的回答並不直接解決目前OP的問題。 –
嗨raja,你可以請寫一個samll示例代碼如何將樣式文本轉換爲集合/ ...謝謝 –