in Sample Applications/HtmlToXamlDemo/HtmlToXamlConverter.cs [2168:2413]
private static void ApplyLocalProperties(XmlElement xamlElement, Hashtable localProperties, bool isBlock)
{
var marginSet = false;
var marginTop = "0";
var marginBottom = "0";
var marginLeft = "0";
var marginRight = "0";
var paddingSet = false;
var paddingTop = "0";
var paddingBottom = "0";
var paddingLeft = "0";
var paddingRight = "0";
string borderColor = null;
var borderThicknessSet = false;
var borderThicknessTop = "0";
var borderThicknessBottom = "0";
var borderThicknessLeft = "0";
var borderThicknessRight = "0";
var propertyEnumerator = localProperties.GetEnumerator();
while (propertyEnumerator.MoveNext())
{
switch ((string) propertyEnumerator.Key)
{
case "font-family":
// Convert from font-family value list into xaml FontFamily value
xamlElement.SetAttribute(XamlFontFamily, (string) propertyEnumerator.Value);
break;
case "font-style":
xamlElement.SetAttribute(XamlFontStyle, (string) propertyEnumerator.Value);
break;
case "font-variant":
// Convert from font-variant into xaml property
break;
case "font-weight":
xamlElement.SetAttribute(XamlFontWeight, (string) propertyEnumerator.Value);
break;
case "font-size":
// Convert from css size into FontSize
xamlElement.SetAttribute(XamlFontSize, (string) propertyEnumerator.Value);
break;
case "color":
SetPropertyValue(xamlElement, TextElement.ForegroundProperty, (string) propertyEnumerator.Value);
break;
case "background-color":
SetPropertyValue(xamlElement, TextElement.BackgroundProperty, (string) propertyEnumerator.Value);
break;
case "text-decoration-underline":
if (!isBlock)
{
if ((string) propertyEnumerator.Value == "true")
{
xamlElement.SetAttribute(XamlTextDecorations, XamlTextDecorationsUnderline);
}
}
break;
case "text-decoration-none":
case "text-decoration-overline":
case "text-decoration-line-through":
case "text-decoration-blink":
// Convert from all other text-decorations values
if (!isBlock)
{
}
break;
case "text-transform":
// Convert from text-transform into xaml property
break;
case "text-indent":
if (isBlock)
{
xamlElement.SetAttribute(XamlTextIndent, (string) propertyEnumerator.Value);
}
break;
case "text-align":
if (isBlock)
{
xamlElement.SetAttribute(XamlTextAlignment, (string) propertyEnumerator.Value);
}
break;
case "width":
case "height":
// Decide what to do with width and height propeties
break;
case "margin-top":
marginSet = true;
marginTop = (string) propertyEnumerator.Value;
break;
case "margin-right":
marginSet = true;
marginRight = (string) propertyEnumerator.Value;
break;
case "margin-bottom":
marginSet = true;
marginBottom = (string) propertyEnumerator.Value;
break;
case "margin-left":
marginSet = true;
marginLeft = (string) propertyEnumerator.Value;
break;
case "padding-top":
paddingSet = true;
paddingTop = (string) propertyEnumerator.Value;
break;
case "padding-right":
paddingSet = true;
paddingRight = (string) propertyEnumerator.Value;
break;
case "padding-bottom":
paddingSet = true;
paddingBottom = (string) propertyEnumerator.Value;
break;
case "padding-left":
paddingSet = true;
paddingLeft = (string) propertyEnumerator.Value;
break;
// NOTE: css names for elementary border styles have side indications in the middle (top/bottom/left/right)
// In our internal notation we intentionally put them at the end - to unify processing in ParseCssRectangleProperty method
case "border-color-top":
borderColor = (string) propertyEnumerator.Value;
break;
case "border-color-right":
borderColor = (string) propertyEnumerator.Value;
break;
case "border-color-bottom":
borderColor = (string) propertyEnumerator.Value;
break;
case "border-color-left":
borderColor = (string) propertyEnumerator.Value;
break;
case "border-style-top":
case "border-style-right":
case "border-style-bottom":
case "border-style-left":
// Implement conversion from border style
break;
case "border-width-top":
borderThicknessSet = true;
borderThicknessTop = (string) propertyEnumerator.Value;
break;
case "border-width-right":
borderThicknessSet = true;
borderThicknessRight = (string) propertyEnumerator.Value;
break;
case "border-width-bottom":
borderThicknessSet = true;
borderThicknessBottom = (string) propertyEnumerator.Value;
break;
case "border-width-left":
borderThicknessSet = true;
borderThicknessLeft = (string) propertyEnumerator.Value;
break;
case "list-style-type":
if (xamlElement.LocalName == XamlList)
{
string markerStyle;
switch (((string) propertyEnumerator.Value).ToLower())
{
case "disc":
markerStyle = XamlListMarkerStyleDisc;
break;
case "circle":
markerStyle = XamlListMarkerStyleCircle;
break;
case "none":
markerStyle = XamlListMarkerStyleNone;
break;
case "square":
markerStyle = XamlListMarkerStyleSquare;
break;
case "box":
markerStyle = XamlListMarkerStyleBox;
break;
case "lower-latin":
markerStyle = XamlListMarkerStyleLowerLatin;
break;
case "upper-latin":
markerStyle = XamlListMarkerStyleUpperLatin;
break;
case "lower-roman":
markerStyle = XamlListMarkerStyleLowerRoman;
break;
case "upper-roman":
markerStyle = XamlListMarkerStyleUpperRoman;
break;
case "decimal":
markerStyle = XamlListMarkerStyleDecimal;
break;
default:
markerStyle = XamlListMarkerStyleDisc;
break;
}
xamlElement.SetAttribute(XamlListMarkerStyle, markerStyle);
}
break;
case "float":
case "clear":
if (isBlock)
{
// Convert float and clear properties
}
break;
case "display":
break;
}
}
if (isBlock)
{
if (marginSet)
{
ComposeThicknessProperty(xamlElement, XamlMargin, marginLeft, marginRight, marginTop, marginBottom);
}
if (paddingSet)
{
ComposeThicknessProperty(xamlElement, XamlPadding, paddingLeft, paddingRight, paddingTop,
paddingBottom);
}
if (borderColor != null)
{
// We currently ignore possible difference in brush colors on different border sides. Use the last colored side mentioned
xamlElement.SetAttribute(XamlBorderBrush, borderColor);
}
if (borderThicknessSet)
{
ComposeThicknessProperty(xamlElement, XamlBorderThickness, borderThicknessLeft,
borderThicknessRight,
borderThicknessTop, borderThicknessBottom);
}
}
}