I have list controls with small, static data sources. For example:
<ItemsControl ItemsSource="{Binding Countries}" .../>
and my view model populates the list:
this.Countries.Add(new Country { Code = "BE", Name = "Belgium" });
this.Countries.Add(new Country { Code = "CA", Name = "Canada" });
// etc.
Is there an alternative way to define the list contents in XAML instead? Something like:
<ItemsControl>
<ItemsControl.ItemsSource>
<somenamespace:list>
<mynamespace:Country Code="BE" Name="Belgium" />
etc.
</somenamespace:list>
</ItemsControl.ItemsSource>
</ItemsControl>
I would actually put the lists in separate resource files and would hope to do ItemsSource="{StaticResource myListOfCountries}"
after defining them as a resource.
I want to do this to lighten the boilerplate code in my VMs. I wonder if it would negatively affect performance as those objects could be created before the view is rendered, while I could otherwise load these later (on navigated to, on view load, ... vs contructor). Any thoughts welcome!