Why when I want to serialize in JSON some sort of control, then recursion?
JavaScriptSerializer serializer = new JavaScriptSerializer(); string json = serializer.Serialize(label1); Why when I want to serialize in JSON some sort of control, then recursion?
JavaScriptSerializer serializer = new JavaScriptSerializer(); string json = serializer.Serialize(label1); Because the control has a link to the parental control, and in addition the list of links to children is closed.
You can write your own wrapper, which has only those properties that you want to keep.
public class ControlWrapper { private Control fControl; public ControlWrapper(Control aControl) { fControl = aControl; } public int Width { get { return fControl.Width; } } ... } JavaScriptSerializer serializer = new JavaScriptSerializer(); string json = serializer.Serialize(new ControlWrapper(label1)); Because you are trying to serialize non-serializable: UI controls. Controls are not intended for serialization, because they have an internal state and internal bindings (for example, event subscriptions) that cannot be saved during serialization.
Do it right, save the model, not the view. Cut corners will not work.
Parent reference to a top-level element (for example, a Grid ) in the model. Or to the list of animations. - VladDOnce you are using wpf, you can try XAML serialization.
Source: https://ru.stackoverflow.com/questions/508582/
All Articles