Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow to serialize CanClose if set to true for LayoutAnchorable instance #187

Merged
merged 1 commit into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
}