DoubleEditBox Firing ValueChanged Twice When Bound To Float

Editors for WPF Forum

Posted 4 years ago by Justin Klein
Version: 17.2.0662
Avatar

I've got a DoubleEditBox in a ListBox's ItemTemplate, like this:

                    <ListBox ItemsSource="{Binding Offsets}" >
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <actiedit:DoubleEditBox Format="F2" Minimum="-1" Maximum="1" SmallChange=".01" Value="{Binding Path=Lengthwise}" ValueChanged="DoubleEditBox_ValueChanged" />
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

The Offsets property is just:

        public List<MyObj> Offsets
        {
            get { return _offsets; }
            set { _offsets = value; RaisePropertyChanged(); }
        }
        private List<MyObj> _offsets = new List<MyObj>();

        public class MyObj
        {
            public float Lengthwise { get; set; }
        }

This works perfectly - however, every time a Lengthwise value changes, the ValueChanged event fires *twice*.  If I change Lengthwise to double, then it works the same, but the event fires once.

Why would binding to float cause every event to be fired a duplicate time, but binding to double not (and is there a way to bind to float while avoiding these duplicate events?)

Comments (2)

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

Hi Justin,

Looking at the stack traces between the two events, it appears that the core WPF Binding is triggering the DoubleEditBox.OnValuePropertyValueChanged (our dependency property change handler) an additional time, probably because the binding is trying to convert between a double and float.  I don't think we can prevent this since it's the Binding that is causing it.

You should just use a SingleEditBox though for this scenario if you are binding to a float (Single type).


Actipro Software Support

Posted 4 years ago by Justin Klein
Avatar

Makes sense, thanks.  And whoops! I searched for FloatEditBox...but not Single... ;)

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.