0
繼承人問題:AutoCompleteBox是邪惡的
爲什麼AutoCompleteBox恨我?我花了至少3天的時間試圖讓ACB在下拉列表中顯示數據。我所得到的是下拉列表中的類名稱。列表框完美地工作。
謝謝您的時間和努力!
繼承人的什麼它做一個圖片:
現在繼承人的XAML爲ListBox
<ListBox Height="100" HorizontalAlignment="Left" Margin="367,81,0,0" Name="ListBox1" VerticalAlignment="Top" Width="184" ItemsSource="{Binding}" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Together}" />
<TextBlock Text=" sadssa" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
下面是該AutoCompleteBox
<sdk:AutoCompleteBox x:Name="atcTextBox" ItemsSource="{Binding}" ValueMemberPath="CountryNumber" FilterMode="StartsWith"
IsTextCompletionEnabled="True" Height="30" MinimumPopulateDelay="0" MinimumPrefixLength="0" Margin="29,225,259,225">
<sdk:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=CountryName}" />
<TextBlock Text="{Binding Path=Together}" />
</StackPanel>
</DataTemplate>
</sdk:AutoCompleteBox.ItemTemplate>
</sdk:AutoCompleteBox>
和代碼Behide的XAML。
Partial Public Class pgMain
Inherits Page
Public Sub New()
InitializeComponent()
Dim a = GetCountry()
ListBox1.ItemsSource = a
atcTextBox.ItemsSource = a
End Sub
Private Function GetCountry() As List(Of Country)
Dim lstCountry As New List(Of Country)()
lstCountry.Add(New Country() With {.CountryName = "India"})
lstCountry.Add(New Country() With {.CountryName = "USA"})
lstCountry.Add(New Country() With {.CountryName = "Australia"})
lstCountry.Add(New Country() With {.CountryName = "Germany"})
lstCountry.Add(New Country() With {.CountryName = "England"})
Return lstCountry
End Function
End Class
Public Class Country
Private m_CountryName As String
Public Property CountryName() As String
Get
Return m_CountryName
End Get
Set(ByVal value As String)
m_CountryName = value
End Set
End Property
Private m_CountryNumber As Integer
Public Property CountryNumber As Integer
Get
Return m_CountryNumber
End Get
Set(value As Integer)
End Set
End Property
Public ReadOnly Property Together
Get
Return m_CountryName & " " & m_CountryNumber.ToString
End Get
End Property
Public Sub New()
m_CountryNumber = Rnd(Timer) * 100
End Sub
End Class
嘗試改變{綁定路徑=國家或地區名稱}和{綁定路徑=共同}到{TempateBinding國家或地區名稱}和{一起TempateBinding}。如果這沒有幫助,請恢復更改並嘗試從xaml中移除設置ItemsSource,並將atcTextBox.ItemsSource = a行替換爲atcTextBox.DataContext = a。讓我知道如果這有助於:)。 – 2012-02-22 19:00:57
那麼,TemplateBinding CountryName會給出錯誤信息,在類型'Control'中找不到CountyName。如果我刪除了XAML的ItemSource並將ItemSource = a替換爲DataContect = a,則下拉效果停止工作。沒有任何顯示)在另一個注意事項..我添加了一個轉換器到AutoCompleteBox.ItemTemplate中的文本框之一,並且轉換器從未被命中(調試) – 2012-02-22 20:13:51
評論#2:我試過這個,它不工作或者http ://msdn.microsoft.com/en-us/library/Dd833083(v = vs.95).aspx – 2012-02-22 20:23:19