ListBox始终自动选择第一项

Shi*_*mmy 13 wpf listbox selecteditem

ListBox的行为是自动选择第一个项目,我该如何避免?

注意:我更喜欢用纯xaml做这个,如果你有任何代码隐藏的想法,那么请不要打扰自己.

Joe*_*Joe 11

尝试

IsSynchronizedWithCurrentItem="False"


Mad*_* D. 6

好吧,我尝试使用FocusManager.FocusedElement ..并使初始焦点成为
列表框本身..所以它有焦点..但没有选择元素..如果你按下或标签..列表框的第一个元素将是选择...

<Window
  ...... 
  FocusManager.FocusedElement="{Binding ElementName=listbox2}">
    <ListBox x:Name="listbox2" HorizontalAlignment="Left"
        VerticalAlignment="Bottom" Width="117.333" Height="116" 
        Margin="30.667,0,0,30">
        <ListBoxItem>Jim</ListBoxItem>
        <ListBoxItem>Mark</ListBoxItem>
        <ListBoxItem>Mandy</ListBoxItem>
</ListBox>
Run Code Online (Sandbox Code Playgroud)


小智 5

remove IsSynchronizedWithCurrentItem ="True"如果需要,可以使用下一个SelectionChanged事件添加它.这解决了我的问题