RadRadioButton binding

7 posts, 1 answers
  1. Fernando
    Fernando avatar
    5 posts
    Member since:
    May 2014

    Posted 25 Mar 2015 Link to this post

    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!









































  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 26 Mar 2015 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Fernando
    Fernando avatar
    5 posts
    Member since:
    May 2014

    Posted 26 Mar 2015 in reply to Pavel R. Pavlov Link to this post

    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.
  5. Answer
    Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 27 Mar 2015 Link to this post

    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.

     
  6. Adrien
    Adrien avatar
    3 posts
    Member since:
    Nov 2015

    Posted 01 Dec 2015 Link to this post

    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

  7. Milena
    Admin
    Milena avatar
    201 posts

    Posted 02 Dec 2015 Link to this post

    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
  8. Adrien
    Adrien avatar
    3 posts
    Member since:
    Nov 2015

    Posted 02 Dec 2015 in reply to Milena Link to this post

    Thank you, it does the trick ! 
Back to Top
UI for WPF is Visual Studio 2017 Ready