ColorTranslator在Silverlight中不存在。
DotPeek顯示System.Drawing.ColorTranslator.ToOle()
下面的源:
public static int ToOle(Color c)
{
if (c.IsKnownColor)
{
switch (c.ToKnownColor())
{
case KnownColor.ActiveBorder:
return -2147483638;
case KnownColor.ActiveCaption:
return -2147483646;
case KnownColor.ActiveCaptionText:
return -2147483639;
case KnownColor.AppWorkspace:
return -2147483636;
case KnownColor.Control:
return -2147483633;
case KnownColor.ControlDark:
return -2147483632;
case KnownColor.ControlDarkDark:
return -2147483627;
case KnownColor.ControlLight:
return -2147483626;
case KnownColor.ControlLightLight:
return -2147483628;
case KnownColor.ControlText:
return -2147483630;
case KnownColor.Desktop:
return -2147483647;
case KnownColor.GrayText:
return -2147483631;
case KnownColor.Highlight:
return -2147483635;
case KnownColor.HighlightText:
return -2147483634;
case KnownColor.HotTrack:
return -2147483622;
case KnownColor.InactiveBorder:
return -2147483637;
case KnownColor.InactiveCaption:
return -2147483645;
case KnownColor.InactiveCaptionText:
return -2147483629;
case KnownColor.Info:
return -2147483624;
case KnownColor.InfoText:
return -2147483625;
case KnownColor.Menu:
return -2147483644;
case KnownColor.MenuText:
return -2147483641;
case KnownColor.ScrollBar:
return int.MaxValue;
case KnownColor.Window:
return -2147483643;
case KnownColor.WindowFrame:
return -2147483642;
case KnownColor.WindowText:
return -2147483640;
case KnownColor.ButtonFace:
return -2147483633;
case KnownColor.ButtonHighlight:
return -2147483628;
case KnownColor.ButtonShadow:
return -2147483632;
case KnownColor.GradientActiveCaption:
return -2147483621;
case KnownColor.GradientInactiveCaption:
return -2147483620;
case KnownColor.MenuBar:
return -2147483618;
case KnownColor.MenuHighlight:
return -2147483619;
}
}
return ColorTranslator.ToWin32(c);
}
這使用也不會在Silverlight中存在的成員(Color.IsKnownColor & Color.ToKnownColor()),所以你可以只使用它使用ToWin32()
方法除了「已知顏色」以外的所有內容:
public static int ToWin32(Color c)
{
return (int) c.R | (int) c.G << 8 | (int) c.B << 16;
}