DoubleEditBox showing incorrect value when in a DataTemplate

Editors for WPF Forum

Posted 7 years ago by Aled Hughes - Principal Software Engineer, Control Techniques Ltd.
Version: 11.1.0542
Avatar

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.

Comments (3)

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Aled,

Sorry I'm not sure offhand why that would be happening.  Yes a sample project would help.  Please reference this thread in your e-mail to our support address.  Thanks!


Actipro Software Support

Posted 7 years ago by Aled Hughes - Principal Software Engineer, Control Techniques Ltd.
Avatar

I have raised a ticket for this. Thanks!

Answer - Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Aled,

Thanks for the sample. I believe we were able to find a workaround for the binding timing issues experienced in this scenario. The fix will be in the next build.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.