Data-binding a collection of radio buttons

3 posts, 0 answers
  1. Richard
    Richard avatar
    30 posts
    Member since:
    Oct 2010

    Posted 23 Sep 2011 Link to this post

    Hi,


    Is it possible to bind a collection of RadRadioButton to a view model property? I'd like to avoid hard-coding the different options in the XAML.

    I tried the following - it generates a button for each item, but the buttons are grayed out and cannot be selected:

    <ItemsControl ItemsSource="{Binding AllOrderTypes}" >
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
               <telerik:RadRadioButton GroupName="OrderType" Content="{Binding}" Click="OrderTypeButtonClick" />                                                   
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

    Is there a better way?


    Thanks for your help,
    Richard
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 28 Sep 2011 Link to this post

    Hi Richard,

     I modified your solution a so that the RadioButtons' Content property is properly bound to a ViewModel's string property. Please examine it and let me know if the suggested approach satisfies you.

    Greetings,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Richard
    Richard avatar
    30 posts
    Member since:
    Oct 2010

    Posted 28 Sep 2011 Link to this post

    Hi Petar,

    Thank you! I'll try this out and let you know if I run into any issues.

    Thanks,
    Richard
Back to Top