/// <summary> /// 获取特定状态的外观属性 /// </summary> /// <param name="state"></param> /// <returns></returns> private CcAppearance GetAppearance(CcCtrlState state) { CcAppearance appearance = null; switch (state) { case CcCtrlState.Disabled: appearance = ctrl.Appearances.DisabledAppearance; break; case CcCtrlState.Hovered: appearance = ctrl.Appearances.HoveredAppearance; break; case CcCtrlState.Pressed: appearance = ctrl.Appearances.PressedAppearance; break; case CcCtrlState.Focused: appearance = ctrl.Appearances.FocusedAppearance; break; case CcCtrlState.Normal: default: break; } return((appearance?.IsEmpty ?? true) ? ctrl.Appearances.Appearance : appearance); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (null == value) { return(new CcAppearances()); } //从字符串解析 if (value is string stringValue) { if (stringValue.Length <= 0) { return(new CcAppearances()); } CcAppearance normal = null; CcAppearance disabled = null; CcAppearance hovered = null; CcAppearance focused = null; CcAppearance pressed = null; stringValue.Split(Separator).ForEach(s => { if (s.StartsWith(KeyNormal)) { normal = (CcAppearance)AppearanceConverter.ConvertFromString(context, culture, s.Substring(KeyNormal.Length)); } else if (s.StartsWith(KeyDisabled)) { disabled = (CcAppearance)AppearanceConverter.ConvertFromString(context, culture, s.Substring(KeyDisabled.Length)); } else if (s.StartsWith(KeyHovered)) { hovered = (CcAppearance)AppearanceConverter.ConvertFromString(context, culture, s.Substring(KeyHovered.Length)); } else if (s.StartsWith(KeyFocused)) { focused = (CcAppearance)AppearanceConverter.ConvertFromString(context, culture, s.Substring(KeyFocused.Length)); } else if (s.StartsWith(KeyPressed)) { pressed = (CcAppearance)AppearanceConverter.ConvertFromString(context, culture, s.Substring(KeyPressed.Length)); } }); return(new CcAppearances { Appearance = normal, DisabledAppearance = disabled, FocusedAppearance = focused, HoveredAppearance = hovered, PressedAppearance = pressed, }); } return(base.ConvertFrom(context, culture, value)); }