I have a static collection Networks
:
public class NetworkSettings
{
private static List<NetworkSetting> _networks;
public static IList<NetworkSetting> Networks
{
get
{
if (_networks == null)
{
_networks = new List<NetworkSetting>
{
new NetworkSetting(),
...
...
}
}
return _networks;
}
}
So far so good. This class is initialised, and valid.
When I bind to it from a Picker with:
[View]
<xmlns:models="clr-namespace:AppName.Models" />
<Picker ItemsSource="{x:Static models:NetworkSettings.Networks}"
SelectedItem="{Binding SelectedNetworkSetting, Mode=TwoWay}" />
I get a NullReference exception (something to do with the ItemsSource).
But if I bind to the ViewModel version of the same data:
[ViewModel]
public IList<NetworkSetting> NetworkSettings => Models.NetworkSettings.Networks;
[View]
<Picker ItemsSource="{Binding NetworkSettings}"
SelectedItem="{Binding SelectedNetworkSetting, Mode=TwoWay}" />
..then everything is fine.
What's the difference? Why does it accept the static binding?
Try to change
to
it will work.