This is a migrated thread and some comments may be shown as answers.

Broken binding to 'Maximum' property

3 Answers 196 Views
NumericUpDown
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 03 Jul 2010, 06:12 PM

Summary: Setting the 'Maximum' property to a value less than the 'Minimum' property causes any binding on the

'Maximum' property to break.

I have a control that has the following bindings:

<telerik:RadNumericUpDown

Minimum="0"

Maximum="{Binding Path=SnapshotCount, ElementName=GameDisplay, Mode=OneWay, Converter={StaticResource

SnapshotCountToMaxIndexConverter}}"

Value="{Binding Path=SnapshotIndex, ElementName=GameDisplay, Mode=TwoWay}"

/>

The problem is that when the SnapshotCountToMaxIndexConverter converter returns a value less than the minimum (in my particular case it was returning -1) then the following code is triggered to execute in RadRangeBase.cs:

 

private void CoerceMaximum()

{

if (this.Maximum < this.Minimum)

{

this.SetValue(MaximumProperty, this.Minimum);

}

 

This appears to break the binding because afterwardsI can see via breakpoints that the

OnMaximumPropertyChanged() method is no longer called.

The net effect of this is that the control becomes unusable because the only value that can then be entered into the field is the minimum value since the minimum and the maximum values are the same and the binding doesn't update what the maximum should be.

 

Interestly, I also have the exact same binding on a RadSlider() and the binding does not appear to break for that control.

NOTE: This problem is easy to avoid by ensuring that you never specify a maximum value that is less than the minimum.

PS: I love the controls by the way.

3 Answers, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 08 Jul 2010, 08:35 AM
Hello William,

Thank you for contacting us.

To make it work you will have to set the Binding Mode of the Maximum property to TwoWay. In that way the binding won't break when the maximum value is less than the minimum.

If you have further questions please let us know.

Kind regards,
Konstantina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
William
Top achievements
Rank 1
answered on 14 Jul 2010, 07:56 AM
Hi Konstantina,
Thank you for the reply but the solution you suggest won't work for me.

1. The business logic is such that the maximum value is defined by the object being bound to and it would be undesirable for the control to be able to change its value. Thus a two way binding is undesirable.
2. Even if this was something that was desirable to do, it is not possible since the bound property does not have a setter.

Also, I'd like to point out that this does not explain why the binding works for the RadSlider control when the bindings are identical to the ones used by the RadNumericUpDown control.

Enclosed for reference are the xaml declarations for both:

 

 

<telerik:RadSlider

 

 

 

Grid.Row="0"

 

 

 

Grid.ColumnSpan="2"

 

 

 

HorizontalAlignment="Stretch"

 

 

 

Minimum="0"

 

 

 

Maximum="{Binding Path=SnapshotCount, ElementName=GameDisplay, Mode=OneWay, Converter={StaticResource SnapshotCountToMaxIndexConverter}}"

 

 

 

Value="{Binding Path=SnapshotIndex, ElementName=GameDisplay, Mode=TwoWay}"

 

 

 

VerticalAlignment="Center"

 

 

 

/>

 

 


 

 

<telerik:RadNumericUpDown

 

 

 

Grid.Row="1"

 

 

 

Grid.Column="1"

 

 

 

IsInteger="True"

 

 

 

Minimum="0"

 

 

 

Maximum="{Binding Path=SnapshotCount, ElementName=GameDisplay, Mode=OneWay, Converter={StaticResource SnapshotCountToMaxIndexConverter}}"

 

 

 

Value="{Binding Path=SnapshotIndex, ElementName=GameDisplay, Mode=TwoWay}"

 

 

 

VerticalAlignment="Center"

 

 

 

/>

 

 


Best regards,
Pete
0
Konstantina
Telerik team
answered on 14 Jul 2010, 04:09 PM
Hi William,

Thank you for your reply.

When the Mode is set to OneWay the binding is lost. For now in your case you have 2 options:
1) To set the binding to TwoWay.
2) To make sure that the Maximum is never less than the Minimum.
We will research further the issue and provide a fix for it in one of our future releases. You can track this status in our Public Issue Tracking System with ID=2668. You can vote for it and see when it is going to be fixed.

If you have further questions please feel free to contact us again.

Sincerely yours,
Konstantina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
NumericUpDown
Asked by
William
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
William
Top achievements
Rank 1
Share this question
or