protected override void AfterDeserialize(XElement xml) { base.AfterDeserialize(xml); // At one point, a field called "ConvertedFromOld" was introduced instead of increasing Version to 2. The following is a fix for this. if (xml.Element("ConvertedFromOld") != null && xml.Element("ConvertedFromOld").Value == "True") { SavedByVersion = 2; } // Upgrade to v2 if (SavedByVersion < 2) { SavedByVersion = 2; AnchorRaw anchor; if (LeftAnchor && RightAnchor) { X = ((Left + Right) / 2).ToString(); anchor = AnchorRaw.Center; } else if (LeftAnchor) { X = (Left).ToString(); anchor = AnchorRaw.Left; } else if (RightAnchor) { X = (Right).ToString(); anchor = AnchorRaw.Right; } else { X = (80 / 2).ToString(); // ok to hard-code 80 because that was the IconWidth of all styles as old as this one anchor = AnchorRaw.Center; } if (TopAnchor && BottomAnchor) { Y = ((Top + Bottom) / 2).ToString(); anchor |= AnchorRaw.Mid; } else if (TopAnchor) { Y = Top.ToString(); anchor |= AnchorRaw.Top; } else if (BottomAnchor) { Y = Bottom.ToString(); anchor |= AnchorRaw.Bottom; } else { Y = (24 / 2).ToString(); // ok to hard-code 24 because that was the IconHeight of all styles as old as this one anchor |= AnchorRaw.Mid; } Anchor = (Anchor)anchor; switch (SizeMode) { case SizeModeOld.NoChange: SizeMode2 = SizeMode2.NoChange; break; case SizeModeOld.ByPercentage: SizeMode2 = SizeMode2.ByPercentage; break; case SizeModeOld.BySizeWidthOnly: SizeMode2 = SizeMode2.BySizeWidthOnly; break; case SizeModeOld.BySizeHeightOnly: SizeMode2 = SizeMode2.BySizeHeightOnly; break; case SizeModeOld.BySizeWidthHeightStretch: SizeMode2 = SizeMode2.BySizeStretch; break; case SizeModeOld.ByPosLeftRight: SizeMode2 = SizeMode2.BySizeWidthOnly; Width = (Right - Left + 1).ToString(); break; case SizeModeOld.ByPosTopBottom: SizeMode2 = SizeMode2.BySizeHeightOnly; Height = (Bottom - Top + 1).ToString(); break; case SizeModeOld.ByPosAllFit: SizeMode2 = SizeMode2.BySizeFit; Width = (Right - Left + 1).ToString(); Height = (Bottom - Top + 1).ToString(); break; case SizeModeOld.ByPosAllStretch: SizeMode2 = SizeMode2.BySizeStretch; Width = (Right - Left + 1).ToString(); Height = (Bottom - Top + 1).ToString(); break; } } Left = Right = Top = Bottom = 0; LeftAnchor = RightAnchor = TopAnchor = BottomAnchor = false; SizeMode = default(SizeModeOld); }
protected override void AfterXmlDeclassify(XElement xml) { base.AfterXmlDeclassify(xml); // At one point, a field called "ConvertedFromOld" was introduced instead of increasing Version to 2. The following is a fix for this. if (xml.Element("ConvertedFromOld") != null && xml.Element("ConvertedFromOld").Value == "True") SavedByVersion = 2; // Upgrade to v2 if (SavedByVersion < 2) { SavedByVersion = 2; AnchorRaw anchor; if (LeftAnchor && RightAnchor) { X = (Left + Right) / 2; anchor = AnchorRaw.Center; } else if (LeftAnchor) { X = Left; anchor = AnchorRaw.Left; } else if (RightAnchor) { X = Right; anchor = AnchorRaw.Right; } else { X = 80 / 2; // ok to hard-code 80 because that was the IconWidth of all styles as old as this one anchor = AnchorRaw.Center; } if (TopAnchor && BottomAnchor) { Y = (Top + Bottom) / 2; anchor |= AnchorRaw.Mid; } else if (TopAnchor) { Y = Top; anchor |= AnchorRaw.Top; } else if (BottomAnchor) { Y = Bottom; anchor |= AnchorRaw.Bottom; } else { Y = 24 / 2; // ok to hard-code 24 because that was the IconHeight of all styles as old as this one anchor |= AnchorRaw.Mid; } Anchor = (Anchor) anchor; switch (SizeMode) { case SizeModeOld.NoChange: SizeMode2 = SizeMode2.NoChange; break; case SizeModeOld.ByPercentage: SizeMode2 = SizeMode2.ByPercentage; break; case SizeModeOld.BySizeWidthOnly: SizeMode2 = SizeMode2.BySizeWidthOnly; break; case SizeModeOld.BySizeHeightOnly: SizeMode2 = SizeMode2.BySizeHeightOnly; break; case SizeModeOld.BySizeWidthHeightStretch: SizeMode2 = SizeMode2.BySizeStretch; break; case SizeModeOld.ByPosLeftRight: SizeMode2 = SizeMode2.BySizeWidthOnly; Width = Right - Left + 1; break; case SizeModeOld.ByPosTopBottom: SizeMode2 = SizeMode2.BySizeHeightOnly; Height = Bottom - Top + 1; break; case SizeModeOld.ByPosAllFit: SizeMode2 = SizeMode2.BySizeFit; Width = Right - Left + 1; Height = Bottom - Top + 1; break; case SizeModeOld.ByPosAllStretch: SizeMode2 = SizeMode2.BySizeStretch; Width = Right - Left + 1; Height = Bottom - Top + 1; break; } } Left = Right = Top = Bottom = 0; LeftAnchor = RightAnchor = TopAnchor = BottomAnchor = false; SizeMode = default(SizeModeOld); }