private BarsPeriod _barsPeriod;
public BarsPeriod BarsPeriod
{
get => _barsPeriod;
set
{
if (!EqualityComparer<BarsPeriod>.Default.Equals(_barsPeriod, value))
{
TheIntervalSelector.Interval = _barsPeriod = value;
RefreshHeader();
PropagateIntervalChange(value);
}
}
}
private void TheIntervalSelector_OnIntervalChanged(object sender, BarsPeriodEventArgs e)
{
BarsPeriod = e.BarsPeriod;
}
protected override void Save(XElement element)
{
if (element == null)
return;
// save the currently selected interval
if (BarsPeriod != null)
{
var intervalElement = new XElement("Interval");
BarsPeriod.ToXml(intervalElement); // does not serialize BarsPeriod.BarsPeriodType because the property is adorned with XmlIgnore!!!
element.Add(intervalElement);
}
}
protected override void Restore(XElement element)
{
if (element == null)
return;
// restore the previously selected interval
XElement intervalElement = element.Element("Interval");
if (intervalElement != null && !string.IsNullOrEmpty(intervalElement.Value))
BarsPeriod = BarsPeriod.FromXml(intervalElement); // does not deserialize BarsPeriod.BarsPeriodType because the property is adorned with XmlIgnore!!!
}
However, because BarsPeriod.BarsPeriodType is adorned with the XmlIgnore attribute it is not serialised. This results in incorrect IntervalSelector state when the workspace is restored:
IntervalSelector with 10 Seconds selected:
BarsPeriod properties at the point of serialization:
BarsPeriod serialized XML:
Because of the above, after the workspace is restored the IntervalSelector now shows 10 Minutes selected, not 10 Seconds:
So how are you supposed to save and restore the BarsPeriod provided by the IntervalSelector?


Comment