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

Data-binding a collection of radio buttons

2 Answers 310 Views
Buttons
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 23 Sep 2011, 06:43 PM
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 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 28 Sep 2011, 04:45 PM
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 >>

0
Richard
Top achievements
Rank 1
answered on 28 Sep 2011, 07:56 PM
Hi Petar,

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

Thanks,
Richard
Tags
Buttons
Asked by
Richard
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Richard
Top achievements
Rank 1
Share this question
or