Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Auto complete text box problem

Auto complete text box problem

Scheduled Pinned Locked Moved WPF
wpfwcfhelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    columbos14927
    wrote on last edited by
    #1

    Hello, Im using the

    System.Windows.Controls.AutoCompleteBox

    Here is my XAML code:

    And here is my code behind the XAML:

    public partial class MainWindow : Window
    {
    private List myList;

        public List MyList
        {
            get { return myList; }
        }
    
        public MainWindow()
        {
            InitializeComponent();
    
            myList = new List
                             {
                                 "Macedonia",
                                 "Madagascar",
                                 "Malawi",
                                 "Malaysia",
                                 "Maldives",
                                 "Mali",
                                 "Malta",
                                 "Marshall Islands",
                                 "Mauritania",
                                 "Mauritius",
                                 "Mexico",
                                 "Micronesia",
                                 "Moldova",
                                 "Monaco",
                                 "Mongolia",
                                 "Montenegro",
                                 "Morocco",
                                 "Mozambique",
                                 "Myanmar"
                             };
            //autocompleteBox.ItemsSource = myList;
        }
    }
    

    When i ran this code the auto complete text box doesn't auto completes. But when i uncomment this line:

    //autocompleteBox.ItemsSource = myList;

    And removed this one:

    ItemsSource="{Binding MyList}"

    From the XAML, the auto complete text box works fine. What i'm missing? Thanks

    Richard DeemingR 1 Reply Last reply
    0
    • C columbos14927

      Hello, Im using the

      System.Windows.Controls.AutoCompleteBox

      Here is my XAML code:

      And here is my code behind the XAML:

      public partial class MainWindow : Window
      {
      private List myList;

          public List MyList
          {
              get { return myList; }
          }
      
          public MainWindow()
          {
              InitializeComponent();
      
              myList = new List
                               {
                                   "Macedonia",
                                   "Madagascar",
                                   "Malawi",
                                   "Malaysia",
                                   "Maldives",
                                   "Mali",
                                   "Malta",
                                   "Marshall Islands",
                                   "Mauritania",
                                   "Mauritius",
                                   "Mexico",
                                   "Micronesia",
                                   "Moldova",
                                   "Monaco",
                                   "Mongolia",
                                   "Montenegro",
                                   "Morocco",
                                   "Mozambique",
                                   "Myanmar"
                               };
              //autocompleteBox.ItemsSource = myList;
          }
      }
      

      When i ran this code the auto complete text box doesn't auto completes. But when i uncomment this line:

      //autocompleteBox.ItemsSource = myList;

      And removed this one:

      ItemsSource="{Binding MyList}"

      From the XAML, the auto complete text box works fine. What i'm missing? Thanks

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      You don't appear to be setting the DataContext[^] anywhere. In the constructor, after you've created the list, try adding:

      DataContext = this;


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups