本文整理汇总了C#中IElement.Style方法的典型用法代码示例。如果您正苦于以下问题:C# IElement.Style方法的具体用法?C# IElement.Style怎么用?C# IElement.Style使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IElement
的用法示例。
在下文中一共展示了IElement.Style方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderElement
public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
{
var parentContainer = (parent as RichTextBlockContainer).Get();
Span span = new Span();
Underline underline = null;
var textDecoration = element.Style("text-decoration");
if (!string.IsNullOrEmpty(textDecoration))
{
if (textDecoration == "underline")
{
underline = new Underline();
underline.Inlines.Add(span);
}
}
var color = element.Style("color");
if (string.IsNullOrEmpty(color) == false)
{
color = color.Trim().TrimStart('#');
if (color.Length == 6)
{
var sR = color.Substring(0, 2);
var sG = color.Substring(2, 2);
var sB = color.Substring(4, 2);
byte r, g, b;
if (byte.TryParse(sR, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out r)
&& byte.TryParse(sG, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out g)
&& byte.TryParse(sB, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out b))
{
var value = Color.FromArgb(255, r, g, b);
if (value != Colors.White && value != Colors.Black)
{
if (underline != null)
{
underline.Foreground = new SolidColorBrush(value);
}
else
{
span.Foreground = new SolidColorBrush(value);
}
}
}
}
}
var fontSize = element.Style("font-size");
if (!string.IsNullOrEmpty(fontSize))
{
fontSize = fontSize.Replace("px", "");
if (underline != null)
{
underline.FontSize = double.Parse(fontSize);
}
else
{
span.FontSize = double.Parse(fontSize);
}
}
var fontWeight = element.Style("font-weight");
if (!string.IsNullOrEmpty(fontWeight))
{
if (underline != null)
{
underline.FontWeight = FontWeights.Bold;
}
else
{
span.FontWeight = FontWeights.Bold;
}
}
var textAlign = element.Style("text-align");
if (!string.IsNullOrEmpty(textAlign))
{
if (textAlign == "left")
{
parentContainer.TextAlignment = Windows.UI.Xaml.TextAlignment.Left;
}
else if (textAlign == "right")
{
parentContainer.TextAlignment = Windows.UI.Xaml.TextAlignment.Right;
}
else
{
parentContainer.TextAlignment = Windows.UI.Xaml.TextAlignment.Center;
}
}
var textStyle = element.Style("text-style");
if (!string.IsNullOrEmpty(textStyle))
{
if (textStyle == "italic")
{
if (underline != null)
{
underline.FontStyle = FontStyle.Italic;
//.........这里部分代码省略.........