|
using AngleSharp.DOM.Collections;
using AngleSharp.DOM.Css;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Samples.ViewModels
{
public class CssRuleViewModel : BaseViewModel
{
ObservableCollection<CssRuleViewModel> children;
String name;
String typeName;
public CssRuleViewModel(CSSRule rule)
{
Init(rule);
switch (rule.Type)
{
case CssRule.FontFace:
var font = (CSSFontFaceRule)rule;
name = "@font-face";
Populate(font.CssRules);
break;
case CssRule.Keyframe:
var keyframe = (CSSKeyframeRule)rule;
name = keyframe.KeyText;
Populate(keyframe.Style);
break;
case CssRule.Keyframes:
var keyframes = (CSSKeyframesRule)rule;
name = "@keyframes " + keyframes.Name;
Populate(keyframes.CssRules);
break;
case CssRule.Media:
var media = (CSSMediaRule)rule;
name = "@media " + media.ConditionText;
Populate(media.CssRules);
break;
case CssRule.Page:
var page = (CSSPageRule)rule;
name = "@page " + page.SelectorText;
Populate(page.Style);
break;
case CssRule.Style:
var style = (CSSStyleRule)rule;
name = style.SelectorText;
Populate(style.Style);
break;
case CssRule.Supports:
var support = (CSSSupportsRule)rule;
name = "@supports " + support.ConditionText;
Populate(support.CssRules);
break;
default:
name = rule.CssText;
break;
}
}
public CssRuleViewModel(CSSProperty declaration)
{
Init(declaration);
name = declaration.Name;
children.Add(new CssRuleViewModel(declaration.Value));
}
public CssRuleViewModel(CSSValue value)
{
Init(value);
name = value.CssText;
}
void Init(Object o)
{
children = new ObservableCollection<CssRuleViewModel>();
typeName = o.GetType().Name;
}
void Populate(CSSStyleDeclaration declarations)
{
foreach (var declaration in declarations)
children.Add(new CssRuleViewModel(declaration));
}
void Populate(CSSRuleList rules)
{
foreach (var rule in rules)
children.Add(new CssRuleViewModel(rule));
}
public String Name
{
get { return name; }
set { name = value; }
}
public String TypeName
{
get { return typeName; }
set { typeName = value; }
}
public ObservableCollection<CssRuleViewModel> Children
{
get { return children; }
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Florian lives in Munich, Germany. He started his programming career with Perl. After programming C/C++ for some years he discovered his favorite programming language C#. He did work at Siemens as a programmer until he decided to study Physics.
During his studies he worked as an IT consultant for various companies. After graduating with a PhD in theoretical particle Physics he is working as a senior technical consultant in the field of home automation and IoT.
Florian has been giving lectures in C#, HTML5 with CSS3 and JavaScript, software design, and other topics. He is regularly giving talks at user groups, conferences, and companies. He is actively contributing to open-source projects. Florian is the maintainer of AngleSharp, a completely managed browser engine.