本文整理汇总了C#中Style.Apply方法的典型用法代码示例。如果您正苦于以下问题:C# Style.Apply方法的具体用法?C# Style.Apply怎么用?C# Style.Apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Style
的用法示例。
在下文中一共展示了Style.Apply方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddElement
void AddElement (IList<Element> list, XElement e, Pen inheritPen, Brush inheritBrush)
{
//
// Style
//
Element r = null;
Style eStyle = new Style();
ApplyStyle (e.Attributes ().ToDictionary (k => k.Name.LocalName, v => v.Value), eStyle);
var style = ReadString (e.Attribute ("style"));
if (!string.IsNullOrWhiteSpace (style)) {
ApplyStyle (style, eStyle);
}
if (!eStyle.hasPen) eStyle.pen = inheritPen;
if (!eStyle.hasBrush) eStyle.brush = inheritBrush;
//var id = ReadString (e.Attribute ("id"));
//
// Elements
//
switch (e.Name.LocalName) {
case "text":
{
var x = ReadNumber (e.Attribute ("x"));
var y = ReadNumber (e.Attribute ("y"));
var font = new Font ();
var fontFamily = ReadTextFontFamily(e);
if (!string.IsNullOrEmpty(fontFamily))
font.Family = fontFamily;
var fontSize = ReadTextFontSize(e);
if (fontSize >= 0)
font.Size = fontSize;
TextAlignment textAlignment = ReadTextAlignment(e);
var txt = new Text (new Rect (new Point (x, y), new Size (double.MaxValue, double.MaxValue)), font, textAlignment, eStyle.pen, eStyle.brush);
ReadTextSpans (txt, e);
r = txt;
}
break;
case "rect":
{
var x = ReadNumber (e.Attribute ("x"));
var y = ReadNumber (e.Attribute ("y"));
var width = ReadNumber (e.Attribute ("width"));
var height = ReadNumber (e.Attribute ("height"));
var rx = ReadNumber (e.Attribute ("rx"));
var ry = ReadNumber (e.Attribute ("ry"));
if (ry == 0) {
ry = rx;
}
r = new Rectangle (new Rect (new Point (x, y), new Size (width, height)), new Size (rx, ry), eStyle.pen, eStyle.brush);
}
break;
case "ellipse":
{
var cx = ReadNumber (e.Attribute ("cx"));
var cy = ReadNumber (e.Attribute ("cy"));
var rx = ReadNumber (e.Attribute ("rx"));
var ry = ReadNumber (e.Attribute ("ry"));
r = new Ellipse (new Point (cx - rx, cy - ry), new Size (2 * rx, 2 * ry), eStyle.pen, eStyle.brush);
}
break;
case "circle":
{
var cx = ReadNumber (e.Attribute ("cx"));
var cy = ReadNumber (e.Attribute ("cy"));
var rr = ReadNumber (e.Attribute ("r"));
r = new Ellipse (new Point (cx - rr, cy - rr), new Size (2 * rr, 2 * rr), eStyle.pen, eStyle.brush);
}
break;
case "path":
{
var dA = e.Attribute ("d");
if (dA != null && !string.IsNullOrWhiteSpace (dA.Value)) {
var p = new Path (eStyle.pen, eStyle.brush);
ReadPath (p, dA.Value);
r = p;
}
}
break;
case "polygon":
{
var pA = e.Attribute ("points");
if (pA != null && !string.IsNullOrWhiteSpace (pA.Value)) {
var path = new Path (eStyle.pen, eStyle.brush);
ReadPoints (path, pA.Value, true);
r = path;
}
}
break;
case "polyline":
{
var pA = e.Attribute ("points");
if (pA != null && !string.IsNullOrWhiteSpace (pA.Value)) {
var path = new Path (eStyle.pen, eStyle.brush);
ReadPoints (path, pA.Value, false);
r = path;
}
}
break;
case "g":
//.........这里部分代码省略.........