2011-04-21 63 views
0

我是WPF的新手。我有自动完成框。当我输入搜索文本时,下拉列表被填充。它包含项目。我可以选择这些项目并通过下载保存到数据库中。但项目不可见。这里是我的代码AutoCompleteBox的Dropdownlist项目不显示在WPF

<AutoComplete:AutoCompleteBox Background="White" Tag="TagName..." Margin="0,0,28.8,0" Name="txtCustomTagName" BorderBrush="#FF104E8B" FontWeight="Normal" BorderThickness="1,1,0,1" FontSize="14" Foreground="#FF104E8B" TextChanged="txtCustomTagName_TextChanged" LostFocus="txtCustomTagName_LostFocus" PreviewTextInput="txtCustomTagName_PreviewTextInput" Populating="txtCustomTagName_Populating" > 
         <AutoComplete:AutoCompleteBox.ItemTemplate> 
         <DataTemplate> 
          <TextBlock /> 
         </DataTemplate> 
         </AutoComplete:AutoCompleteBox.ItemTemplate> 
        </AutoComplete:AutoCompleteBox> 



//Populated Event:- 

private void txtCustomTagName_Populating(object sender, PopulatingEventArgs e) 
    { 
     string strFilePath = ""; 
     string strNewFile = ""; 
     strFilePath += @"../../FIXDictionaries/"; 
     string typedString = txtCustomTagName.Text; ; 
     strNewFile = strFilePath + cmbFIXVerDataDictionary.Text + extension; 
     XDocument xmldoc = XDocument.Load(strNewFile); 


     List<string> tags = new List<string>(); 

     IEnumerable<string> childNames = (from child in xmldoc.Element("fix").Element("fields").Descendants("field") 
         select child.Attribute("name").Value).Distinct().ToList(); 
     foreach (string childName in childNames) 
     { 
     if (childName.StartsWith(typedString, StringComparison.InvariantCultureIgnoreCase)) 
     { 
      tags.Add(childName); 
     } 
     } 
     txtCustomTagName.ItemsSource = tags; 






    } 
    } 

如何做到这一点?

回答

1

我想原因是您使用ItemTemplate与空的TextBlock。或者完全不使用ItemTemplate或者(在你的情况下)用<TextBlock Text="{Binding}" />