Dim dict As New Collections.Generic.Dictionary(Of String, String)
Private Sub MainWindow_Loaded() Handles Me.Loaded
dict.Add("One", "1")
dict.Add("Two", "2")
dict.Add("Three", "3")
lst1.ItemsSource = dict
End Sub
我有一个表格,其中包含一个名为“lst1”的ListBox,它使用“dict”作为项目源:
<ListBox x:Name="lst1">
<ListBox.ItemTemplate>
<DataTemplate>
<Label Content="{Binding Value}"
TextSearch.Text="{Binding Path=Key, Mode=OneWay}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
此外,我有一个非绑定 ListBox,手动填充了一些值:
<ListBox>
<Label TextSearch.Text="One" Content="1" />
<Label TextSearch.Text="Two" Content="2" />
<Label TextSearch.Text="Three" Content="3" />
</ListBox>
当我启动应用程序时,它看起来像这样:
THE QUESTION:
如果我尝试使用键盘通过键入“one”、“two”或“three”来导航项目,则只能在未绑定的列表框中成功。绑定列表框失败。
一些备注: 1.) 如果我在绑定的列表框中按“[”,焦点会以循环方式从项到项进行更改:从1到2,从2到3,从3到1,再从1到2等。 2.) 我已经使用Snoop检查了应用程序。我发现绑定和非绑定列表框之间的一个区别。两个列表框都在ItemsPresenter中设置了Label控件上的TextSearch.Text属性。但是对于未绑定的情况:“TextSearch.Text”属性的“值源”为“Local”。对于绑定的情况:“值源”为“ParentTemplate”。
P.S.(和N.B.) 我知道我可以在列表框上使用TextSearch.TextPath,但这不是我需要的:) 此外,设置ListViewItem的TextSearch.Text属性(使用Style)也无济于事。