
I have a DoubleEditBox hosted within a ContentControl via a DataTemplate that exhibits an unexpected behaviour relating to the maximum value when the binding data context for the control is being changed and a binding converter is being used for the Format property. It's a little difficult to explain, but here goes! --
The Format, Minimum, Maximum and Value properties of DoubleEditBox are all set via a data binding to the underlying object and I have two objects as follows:
Object 1: Minimum=0, Maximum=1, Precision=4, Value=0.1
Object 2: Minimum=0, Maximum=0.65535, Precision=5, Value=0.65535
The display of the Edit control is in a ContentControl like this (the original program did more than this of course):
<ContentControl Content="{Binding TheSelectedItem}">
<ContentControl.ContentTemplate>
<DataTemplate>
<ac:DoubleEditBox Value="{Binding Path=Value, UpdateSourceTrigger=PropertyChanged}"
Maximum="{Binding Maximum}" Minimum="{Binding Minimum}"
Format="{Binding Converter={StaticResource ParamterToNumFormatConverter}}"/>
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
The ParameterToNumFormatConverter is basically this in it's Convert method:
return p.Precision == 0 ? "G" : string.Concat("F", p.Precision);
Now if I set the DataContext of the ContentControl to the first object, it correctly shows the value of 0.1000. If I change the DataContext to the second object it now shows 0.10000 instead of the expected 0.65535 value. Strangely, if object 2 happened to have a Value=0.65534 then the problem doesn't manifest itself.
I can kind of mitigate the problem by two means:
- Don't use a DataTemplate (in my program I have many data templates that I switch between at runtime).
- Put IsAsync on the Value data binding
- Change the Format binding to use {Binding Precision,StringFormat='F{0}'}
Any ideas on why this is happening? I can send a working test project demonstrating it.