01-05-2021 01:20 PM
Hi,
I am trying to configure an editable DateTime axis in a graph using xaml. I have tried the following <ni:AxisDateTime Orientation="Horizontal" InteractionMode="EditRange"/>. However, druing runtime if I try to edit the time axis the values I enter is immediately discarded and the value is set back to default. When using eg. integer axis there is no issue. Am I doing something wrong with the time axis?
Brg.
Oddvar
01-06-2021 03:41 PM
From “immediately discarded”, it sounds like the entered value failed to parse. To investigate the cause, I would suggest attaching a custom edit formatter that uses Parse
instead of TryParse
, so that you can examine any parse exceptions:
public sealed class CustomValueFormatter : GeneralValueFormatter {
public override bool TryParse<TData>( string value, ValuePresenterArgs args, out TData parsedValue ) {
parsedValue = base.Parse<TData>( value, args );
return true;
}
}
Here is how you can assign the custom formatter to your axis in XAML:
<ni:AxisDateTime Orientation="Horizontal" InteractionMode="EditRange">
<ni:AxisDateTime.MajorDivisions>
<ni:RangeLabeledDivisions>
<ni:RangeLabeledDivisions.EditRangeValueFormatter>
<local:CustomValueFormatter />
</ni:RangeLabeledDivisions.EditRangeValueFormatter>
</ni:RangeLabeledDivisions>
</ni:AxisDateTime.MajorDivisions>
</ni:AxisDateTime>
01-29-2021 09:28 AM
Hi Paul,
Thanks! Works without any problems with the CustomValueFormatter. Thus I am not able to investigate what is going wrong in the first place. But as you said, definitely something with the parsing.
Oddvar