How to bind a radiobuttonlist to application settings

WPF Studio, Themes, and Shared Library for WPF Forum

Posted 10 years ago by Bob
Version: 4.5.0487
Avatar
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.Resources>
                <Style TargetType="ListBoxItem">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ListBoxItem">
                                <RadioButton 
                                    Content="{TemplateBinding ContentPresenter.Content}"
                                    Foreground="WhiteSmoke"
                                    IsChecked="{Binding Path=IsSelected, 
                                    RelativeSource={RelativeSource TemplatedParent}, 
                                    Mode=TwoWay}" />
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Style.Resources>
        </Style>
 
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>
                </shared:RadioButtonList>
The problem is that both radiobuttons are selected. Is there a simple way to implement this?

Thanks
Bob

Comments (4)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
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 10 years ago by Bob
Avatar
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 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
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 10 years ago by Bob
Avatar
Thanks,
That was exactly what I was looking for. Sometimes you just make it harder than it really is.
Thanks again
Bob
The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.