Hi,
I have an issue using databinding with the MinValue/MaxValue of the XamNumericSlider. In my actual application I try to bind the MaxValue property while setting the MinValue to 0. However, the MinValue ends up being set to -1. I guessed that this had something to do with the MaxValue being bound to the value 0 (i.e. the same as the MinValue) and tried to use a binding for the MinValue as well. However, even though MaxValue is set correctly by the binding to whatever positive number, the slider's MinValue is stuck at -1.
I have attached a sample application that show the issue. The application sets the MinValue/MaxValue based on databinding, with both source values set to 0. This results in the actual slider MinValue being set to -1. If I then use the 'Increment MaxValue by 1' button to set the MaxValue to a value of at least 1, and then use the 'Set MinValue to MaxValue - 1' button to try to set the MinValue, the slider's MinValue is stuck at -1.
The sample application has a '#define MAX_IT_WORK' directive that can be used to set the initial source MaxValue to 1 rather than 0. In this case, the sample application works as expected, i.e. the MinValue is updated correctly using the button. However, my actual application does still seem to have the issue if I make sure that the MaxValue source is always bigger than 0.
How can I get my bindings to work?
Regards,Leif
Hi Leif,
Thank you for your post. I have been looking into your question and after investigating this behavior I found out that when the ‘MinValue’, ‘MaxValue’ and ‘Value’ properties has the same value, the XamNumericEditor sets the MinValue on the MaxValue – 1 because they cannot be equal(logically this is not correct). This is the design behavior of the control.
Regarding your issue with the ‘Set MinValue to MaxValue - 1’ button you need to bind the ‘MinValue’ and ‘MaxValue’ properties with Mode set to “TwoWay” in order to notify the change like e.g.:
MinValue="{Binding Min, Mode=TwoWay}"
MaxValue="{Binding Max, Mode=TwoWay}"
Please let me know, if you need any further assistance on this matter.
setting the bindings to TwoWay made my code work, but at the cost of adding unneeded code to my View Model: The values for the min/max properties were originally read-only as they are generated by model code. Using a two-way binding made me make dummy setters for these properties, which isn't pretty.
I still find it strange that my main application's MinValue is set to -1, since my bound MaxValue value is always greater than 0 (i.e.always greater than the MinValue). Something in the slider control or the binding framework must obviously set the MaxValue to 0 without being told so by my code.
Also, is it really logically correct for the slider to not allow equal values for MinValue, MaxValue and Value? This sounds like a perfectly valid case to me, i.e. one single allowed value. Setting the MaxValue to less than the MinValue is of course logically wrong though.
I am just checking, if you require any further assistance on this matter.