I have a hard time making it work. The code is in the MVVM application, where I bind the switches to a property in the ViewModel.
I am trying to implement this SO answer
Everything works fine, except that the buttons are arranged vertically. Now this seems like an easy solution, just change the ItemPanelTemplate.
Here is my code:
<ListBox ItemsSource="{Binding ItemOptions}" SelectedItem="{Binding SelectedOption}"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" IsItemsHost="True" /> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.ItemContainerStyle> <Style TargetType="{x:Type ListBoxItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListBoxItem}" > <RadioButton Content="{TemplateBinding Content}" IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsSelected}"/> </ControlTemplate> </Setter.Value> </Setter> </Style> </ListBox.ItemContainerStyle> </ListBox>
However, the elements are kept upright. Any ideas why this does not affect the orientation of the ListBox? What am I missing?
Thanks Jerry
source share