Skip to content

Commit

Permalink
Allow to serialize CanClose if set to true for LayoutAnchorable instance
Browse files Browse the repository at this point in the history
  • Loading branch information
bdachev committed Aug 14, 2020
1 parent 7ae58b8 commit 7804a49
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions source/Components/AvalonDock/Layout/LayoutAnchorable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public class LayoutAnchorable : LayoutContent
public LayoutAnchorable()
{
// LayoutAnchorable will hide by default, not close.
_canClose = false;
// BD: 14.08.2020 Inverting both _canClose and _canCloseDefault to false as anchorables are only hidden but not closed
// That would allow CanClose to be properly serialized if set to true for an instance of LayoutAnchorable
_canClose = _canCloseDefault = false;
}

#endregion Constructors
Expand Down Expand Up @@ -608,4 +610,4 @@ private void UpdateParentVisibility()

#endregion Private Methods
}
}
}
12 changes: 9 additions & 3 deletions source/Components/AvalonDock/Layout/LayoutContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,10 @@ public ImageSource IconSource

#region CanClose

internal bool _canClose = true;
// BD: 14.08.2020 added _canCloseDefault to properly implement inverting _canClose default value in inheritors (e.g. LayoutAnchorable)
// Thus CanClose property will be serialized only when not equal to its default for given class
// With previous code it was not possible to serialize CanClose if set to true for LayoutAnchorable instance
internal bool _canClose = true, _canCloseDefault = true;

public bool CanClose
{
Expand Down Expand Up @@ -557,7 +560,10 @@ public virtual void WriteXml(System.Xml.XmlWriter writer)
if (FloatingHeight != 0.0) writer.WriteAttributeString(nameof(FloatingHeight), FloatingHeight.ToString(CultureInfo.InvariantCulture));

if (IsMaximized) writer.WriteAttributeString(nameof(IsMaximized), IsMaximized.ToString());
if (!CanClose) writer.WriteAttributeString(nameof(CanClose), CanClose.ToString());
// BD: 14.08.2020 changed to check CanClose value against the default in _canCloseDefault
// thus CanClose property will be serialized only when not equal to its default for given class
// With previous code it was not possible to serialize CanClose if set to true for LayoutAnchorable instance
if (CanClose != _canCloseDefault) writer.WriteAttributeString(nameof(CanClose), CanClose.ToString());
if (!CanFloat) writer.WriteAttributeString(nameof(CanFloat), CanFloat.ToString());

if (LastActivationTimeStamp != null) writer.WriteAttributeString(nameof(LastActivationTimeStamp), LastActivationTimeStamp.Value.ToString(CultureInfo.InvariantCulture));
Expand Down Expand Up @@ -757,4 +763,4 @@ protected virtual void InternalDock()

#endregion Internal Methods
}
}
}

0 comments on commit 7804a49

Please sign in to comment.