How to bind a radiobuttonlist to application settings

WPF Studio, Themes, and Shared Library for WPF Forum

Posted 15 years ago by Bob
Version: 4.5.0487
I have a radiobuttonlist that I want to twoway bind to an index that I store in the application settings. The index indicates which radiobutton is selected. I have tried several approches but they don't work.
The Last I have tried is:

       <Style x:Key="RadioButtonListStyle" TargetType="ListBox">
                <Style TargetType="ListBoxItem">
                    <Setter Property="Template">
                            <ControlTemplate TargetType="ListBoxItem">
                                    Content="{TemplateBinding ContentPresenter.Content}"
                                    IsChecked="{Binding Path=IsSelected, 
                                    RelativeSource={RelativeSource TemplatedParent}, 
                                    Mode=TwoWay}" />
with the following for the listitem

                <shared:RadioButtonList Name="DisplayTypeControl" Margin="40,0,10,10" SelectionChanged="DisplayTypeChange_SelectionChanged"
                    IsHitTestVisible="True" Style="{StaticResource RadioButtonListStyle}">
                    <ListBoxItem Name="TimeseriesSelect" IsSelected="{Binding  Source={x:Static properties:Settings.Default}, Path=Default.DataType}">Timeseries</ListBoxItem>
                    <ListBoxItem Name="SpectrumSelect"  IsSelected="{Binding  Source={x:Static properties:Settings.Default}, Path=Default.DataType}">Spectrum</ListBoxItem>
The problem is that both radiobuttons are selected. Is there a simple way to implement this?


Comments (4)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Bob,

I'm not sure I fully understand the problem, but from your code both items in the RadioButtonList have the exact same binding for IsSelected (so the both would be selected or unselected).

If that's not the problem, then please send over a small sample project to our support email and we can take a look.

On a side note, you shouldn't need the Style you listed for the RadioButtonList, as it already provides a Style for the ListBoxItems.

Actipro Software Support

Posted 15 years ago by Bob
What I am trying to do is not track the IsSelected True/False but the index of the listitem that is selected. Does this make sense?
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
I think you might be looking for the SelectedIndex property on the RadioButtonList itself. The RadioButtonList is just a restyled ListBox/Selector, which as a SelectedIndex property (as well as a SelectedItem property).

Actipro Software Support

Posted 15 years ago by Bob
That was exactly what I was looking for. Sometimes you just make it harder than it really is.
Thanks again
The latest build of this product (v24.1.2) was released 0 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.