Here is such a simple task, but on the move did not find a solution. Of course you can, and manually, but this is somehow not human.

  • one
    First, you need to find a list of all countries of the world ... - Pavel Mayorov

2 answers 2

  1. Find a list of countries in machine readable format (xml, json, csv).
  2. Add it to the application as a resource (Embedded resource)
  3. In the application: load the resource via GetType().Assembly.GetManifestResourceStream(...) (call GetType().Assembly.GetManifestResourceNames() in the debugger if you have trouble with the name of the resource)
  4. Get a list of countries from an open resource and pass it to the ItemsSource using any convenient method (direct assignment or via Binding)
  • And why Embedded Resource, and not just Resource? With them you can, in theory, easier. msdn.microsoft.com/en-us/library/9za7fxc7(v=vs.100).aspx - VladD
  • @VladD it works ugly with files. Instead of giving a stream, it loads everything into an array of bytes, which you end up wrapping in the MemoryStream yourself. - Pavel Mayorov
  • There he had a strict typification somewhere, didn't he? - VladD
  • @VladD if we use strict typing - we are returning to the problem "How is it all stuffed? Manually what?" . The idea is just to store data in the format to which they could find. - Pavel Mayorov
  • Oh, that's it! Well, in such cases, I'm not lazy to write a three-line preprocessor, and get the lines in a convenient format that you can feed to the resource editor (well, or manually enter into the .resources file). At the same time, a couple milliseconds in runtime is saved. But this is probably a separate decision. - VladD

Here is everything you need. You can download the required list in advance and work with it, you can load it during the launch of the application, I am sure that this will not affect the speed of your application.

Once and for all:

 <ComboBox Height="..." Name="..." Width="..."> <ComboBoxItem Content="X"/> <ComboBoxItem Content="Y"/> <ComboBoxItem Content="Z"/> ... </ComboBox> 

We read JSON, save the elements in a container, and when the application starts:

 private void Window_Loaded(...) { for_each( ... ) comboBox.Items.Add(...); } 
  • The question was not about that ... - Pavel Mayorov
  • @PavelMayorov, updated. I looked at your answer - plus, I like it more. - isnullxbh