AutoCompleteBox的Dropdownlist项目不会显示在WPF中

时间:2011-04-21 06:15:15

标签: wpf autocomplete

我是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 个答案:

答案 0 :(得分:1)

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

替换它