internal static SaveContext CreateSaveContext(Stylesheet stylesheet) { return(new SaveContext { ShouldSerializeProperty = (o, p) => { return !SaveContext.HasDefaultValue(o, p) && (!(o is Widget) || !HasStylesheetValue((Widget)o, p, stylesheet)); } }); }
public static bool ShouldSerializeProperty(Stylesheet stylesheet, object o, PropertyInfo p) { var asWidget = o as Widget; if (asWidget != null && asWidget.Parent != null && asWidget.Parent is Grid) { var container = asWidget.Parent.Parent; if (container != null && (container is StackPanel || container is SplitPane) && (p.Name == "GridRow" || p.Name == "GridColumn")) { // Skip serializing auto-assigned GridRow/GridColumn for SplitPane and Box containers return(false); } } var asGrid = o as Grid; if (asGrid != null) { var value = p.GetValue(o); if ((p.Name == DefaultColumnProportionName || p.Name == DefaultRowProportionName) && value == Proportion.GridDefault) { return(false); } } var asBox = o as StackPanel; if (asBox != null) { var value = p.GetValue(o); if (p.Name == DefaultProportionName && value == Proportion.StackPanelDefault) { return(false); } } if (SaveContext.HasDefaultValue(o, p)) { return(false); } if (asWidget != null && HasStylesheetValue(asWidget, p, stylesheet)) { return(false); } return(true); }