开发者

AutoCompleteBox's Dropdownlist items is not displayed in WPF

开发者 https://www.devze.com 2023-02-28 07:18 出处:网络
I am new to WPF.I have AutoCompleteBox.When i enter a search text,dropdownlist is populated.It contains items.I am able to selected those items and saved into databse through down or up arrow.But item

I am new to WPF.I have AutoCompleteBox.When i enter a search text,dropdownlist is populated.It contains items.I am able to selected those items and saved into databse through down or up arrow.But items are not visible.Here is my code

<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(chil开发者_如何学GodName);
        }
      }
      txtCustomTagName.ItemsSource = tags;






    }
  }

How to do it?


I suppose the cause is you use ItemTemplate with empty TextBlock. Or don't use ItemTemplate at all or (in your case) replase it with <TextBlock Text="{Binding}" />

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号