2

I have a ListBox with RadioButton inside it of the same GroupName.

Like so:

<ListBox x:Name="AnswerListBox" DataContext="{Binding .}" ItemsSource="{Binding Answers}" Width="auto" HorizontalAlignment="Center" >
    <ListBox.ItemTemplate>
        <DataTemplate>
            <local:spriteToggleButton DataContext="{Binding .}" HorizontalAlignment="Center" Text="{Binding text}" Selected="{Binding selected}" Sprites="{Binding Path=DataContext.UISprites, ElementName=questionField}" IsChecked="{Binding selected, Mode=TwoWay}" GroupName="{Binding Path=DataContext.QuestionTitle, ElementName=questionField}" />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

When I click on a RadioButton it will unselect another in that group, this is fine.

But when I do a swipe down on the ListBox it will select more than one RadioButton which is an unwanted behavior.

There might be more than one way of changing that behavior.

  1. I don't need it to scroll up and down the list as I will only show as many items as will fit on screen. so maybe that behavior can be disabled.

  2. Maybe a callback could incur when the ListBox is scrolled and something could disable selection when dragging in being done.

  3. the DataContext to the listbox is of List<> so is there a way to change the setter of my Selected variable in my List<> so that it unsets the other values in that list.

Claus Jørgensen
  • 25,882
  • 9
  • 87
  • 150
Joseph Le Brech
  • 6,541
  • 11
  • 49
  • 84
  • The DataContext="{Binding .}" is completely unnecessary. The DataContext defaults to inheriting it from the parent element, or template. – Claus Jørgensen Aug 04 '11 at 16:11
  • Ok thanks, removing will make my code cleaner. but i still have that issue i've mentioned. Thanks for the tip though. It's left over code from when nothing worked with some of my DependencyProperties. – Joseph Le Brech Aug 04 '11 at 16:15

1 Answers1

1
  1. Set ScrollViewer.VerticalScrollBarVisibility to "Disabled" on the ListBox element.

  2. In the SelectionChanged event, set the SelectedIndex to -1

  3. You could clear all the other values in the ItemsSource in the SelectionChanged event.

Claus Jørgensen
  • 25,882
  • 9
  • 87
  • 150