开发者

ListBox is selecting more than one item when it is being dragged

开发者 https://www.devze.com 2023-03-26 11:24 出处:网络
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\" Horizont

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="{开发者_如何学JAVABinding 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.


  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.

0

精彩评论

暂无评论...
验证码 换一张
取 消