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

RadRadioButton binding

6 Answers 751 Views
Buttons
This is a migrated thread and some comments may be shown as answers.
Fernando
Top achievements
Rank 1
Fernando asked on 25 Mar 2015, 04:54 PM
Hello,

I have problems binding two radioButtons with a nullable bool property. Here is the code of the buttons:
<StackPanel Style="{StaticResource stackGridPadre}" Orientation="Horizontal">
                <TextBlock Width="350" Style="{StaticResource txtLabel}">Precintaje</TextBlock>
                <telerik:RadRadioButton Name="rbPrecintaje" IsChecked="{Binding Informe.precintaje_ok,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" GroupName="Precintaje">
                    <StackPanel Orientation="Horizontal">
                        <Image Style="{StaticResource imageRadioButton}" Source=".\..\Resources\Images\Ok_28.png"></Image>
                        <Label Style="{StaticResource labelRadioButton}">Si</Label>
                    </StackPanel>
                </telerik:RadRadioButton>
                <telerik:RadRadioButton GroupName="Precintaje">
                    <StackPanel Orientation="Horizontal">
                        <Image Style="{StaticResource imageRadioButton}" Source=".\..\Resources\Images\Ko_28.png"></Image>
                        <Label Style="{StaticResource labelRadioButton}">No</Label>
                    </StackPanel>
                </telerik:RadRadioButton>
                <TextBlock Margin="5,0,0,0" Style="{StaticResource txtLabel}" Width="75">NÂș Precinto</TextBlock>
                <TextBox Style="{StaticResource estiloNormal}" Text="{Binding Informe.numero_precinto}" Width="220"></TextBox>
            </StackPanel>

It works fine when i set the value of OK (the value is saved and it press the OK button when the binding is loaded)
When i set the KO value the property is set to false and save that value but when i load the property with false, the KO button is not pressed.


Is there somethin i am missing or doing wrong? Do i have to set the IsChecked property manually?

Thanks!









































6 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 26 Mar 2015, 02:47 PM
Hi Fernando

Please note that the IsChecked property of the second button is not bound. This means that there is no logic which will send it in checked state when the first button is unchecked. If you need to control the states of both buttons using code you should bind both buttons to your code. This will allow you to follow the state of the buttons and to change them.

Regards,
Pavel R. Pavlov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Fernando
Top achievements
Rank 1
answered on 26 Mar 2015, 02:58 PM
Thanks for your answer Pavel,

I've seen on another post that it was only necesary to bind one of the buttons to the property and it Works when i sabe the data:
    - When i click on OK the property of the object at the VoewModel is set to True
    - When i click on KO the property is set to False
The problema is when the element at the ViewModel changes, the only button that shows as pressed is the OK (if the property is set to true).
I assumed that it would work by setting only one binding.
0
Accepted
Pavel R. Pavlov
Telerik team
answered on 27 Mar 2015, 02:03 PM
Hello,

It is expected that the OK button will be sent in checked state once its IsChecked property is set to true. If you set that property to false, the KO button will not be automatically checked. The reason behind this behavior is the fact that there is no binding to its IsChecked property.

It is as simple as this: if you need to change the state of the KO button using your ViewModel you need to bind its IsChecked property.

Regards,
Pavel R. Pavlov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Adrien
Top achievements
Rank 2
answered on 01 Dec 2015, 10:39 AM

Hello,

 I have the same issue, and I don't understand how to bind the KO button to get the expected behavior...

 Thank you in advance,
Adrien

0
Milena
Telerik team
answered on 02 Dec 2015, 11:12 AM
Hello Adrien,

When 2 or more radio buttons are in the same group and you check one of them, the others go automatically in unchecked state. However, when you only uncheck one of the buttons, even if there are only 2, the second one won't go in checked state. 
In a scenario where you have 2 button and want to bind the IsChecked property to a property of your ViewModel, you can add converter or additional logic to control the buttons behavior and change their states. You can find attached a sample where this approach is demonstrated.

I hope this information helps.

Regards,
Milena
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Adrien
Top achievements
Rank 2
answered on 02 Dec 2015, 01:00 PM
Thank you, it does the trick ! 
Tags
Buttons
Asked by
Fernando
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Fernando
Top achievements
Rank 1
Adrien
Top achievements
Rank 2
Milena
Telerik team
Share this question
or