private static bool getTextComponentAttributes(IvyTextComponent comp, XmlAttribute attr) { String value = attr.Value; if (attr.Name.Equals("text")) { comp.setText(value); } else if (attr.Name.Equals("textAlignment")) { if (value == string.Empty) { throw new EmptyAttributeValueException(); } if (value.Equals("left")) { comp.setTextAlignment(IvyComponent.Alignment.LEFT); } else if (value.Equals("center")) { comp.setTextAlignment(IvyComponent.Alignment.CENTER); } else if (value.Equals("right")) { comp.setTextAlignment(IvyComponent.Alignment.RIGHT); } else { throw new InvalidAttributeException(); } } else if (attr.Name.Equals("verticalTextAlignment")) { if (value == string.Empty) { throw new EmptyAttributeValueException(); } if (value.Equals("top")) { comp.setVerticalTextAlignment(IvyComponent.Alignment.TOP); } else if (value.Equals("center")) { comp.setVerticalTextAlignment(IvyComponent.Alignment.CENTER); } else if (value.Equals("right")) { comp.setVerticalTextAlignment(IvyComponent.Alignment.BOTTOM); } else { throw new InvalidAttributeException(); } } else if (attr.Name.Equals("textColor")) { if (value == string.Empty) { throw new EmptyAttributeValueException(); } try { comp.setTextColor((SolidColorBrush) new BrushConverter().ConvertFromString(value)); } catch (Exception ex) { throw new InvalidAttributeException(); } } else if (attr.Name.Equals("padding")) { value = attr.Value; if (value == string.Empty) { throw new EmptyAttributeValueException(); } String[] paddingValues = value.Split(','); for (int i = 0; i < paddingValues.Length; i++) { paddingValues[i] = paddingValues[i].Trim(); } if (paddingValues.Length == 1) { try { comp.setPadding(int.Parse(paddingValues[0])); } catch (Exception ex) { throw new InvalidAttributeTypeException(); } } else if (paddingValues.Length == 2) { try { comp.setPadding(int.Parse(paddingValues[0]), int.Parse(paddingValues[1])); } catch (Exception ex) { throw new InvalidAttributeTypeException(); } } else if (paddingValues.Length == 4) { try { comp.setPadding(int.Parse(paddingValues[0]), int.Parse(paddingValues[1]), int.Parse(paddingValues[2]), int.Parse(paddingValues[3])); } catch (Exception ex) { throw new InvalidAttributeTypeException(); } } else { throw new InvalidAttributeValueException(); } } else { return(false); } return(true); }
private static bool getTextComponentAttributes(IvyTextComponent comp, XmlAttribute attr) { String value = attr.Value; if (attr.Name.Equals("text")) { comp.setText(value); } else if (attr.Name.Equals("textAlignment")) { if (value == string.Empty) { throw new EmptyAttributeValueException(); } if (value.Equals("left")) { comp.setTextAlignment(IvyComponent.Alignment.LEFT); } else if (value.Equals("center")) { comp.setTextAlignment(IvyComponent.Alignment.CENTER); } else if (value.Equals("right")) { comp.setTextAlignment(IvyComponent.Alignment.RIGHT); } else { throw new InvalidAttributeException(); } } else if (attr.Name.Equals("verticalTextAlignment")) { if (value == string.Empty) { throw new EmptyAttributeValueException(); } if (value.Equals("top")) { comp.setVerticalTextAlignment(IvyComponent.Alignment.TOP); } else if (value.Equals("center")) { comp.setVerticalTextAlignment(IvyComponent.Alignment.CENTER); } else if (value.Equals("right")) { comp.setVerticalTextAlignment(IvyComponent.Alignment.BOTTOM); } else { throw new InvalidAttributeException(); } } else if (attr.Name.Equals("textColor")) { if (value == string.Empty) { throw new EmptyAttributeValueException(); } try { comp.setTextColor((SolidColorBrush)new BrushConverter().ConvertFromString(value)); } catch (Exception ex) { throw new InvalidAttributeException(); } } else if (attr.Name.Equals("padding")) { value = attr.Value; if (value == string.Empty) { throw new EmptyAttributeValueException(); } String[] paddingValues = value.Split(','); for (int i = 0; i < paddingValues.Length; i++) { paddingValues[i] = paddingValues[i].Trim(); } if (paddingValues.Length == 1) { try { comp.setPadding(int.Parse(paddingValues[0])); } catch (Exception ex) { throw new InvalidAttributeTypeException(); } } else if (paddingValues.Length == 2) { try { comp.setPadding(int.Parse(paddingValues[0]), int.Parse(paddingValues[1])); } catch (Exception ex) { throw new InvalidAttributeTypeException(); } } else if (paddingValues.Length == 4) { try { comp.setPadding(int.Parse(paddingValues[0]), int.Parse(paddingValues[1]), int.Parse(paddingValues[2]), int.Parse(paddingValues[3])); } catch (Exception ex) { throw new InvalidAttributeTypeException(); } } else { throw new InvalidAttributeValueException(); } } else { return false; } return true; }