I'm finding Xamarin Forms XAML very frustrating.
If I use this syntax...
<ContentView.Resources>
<local:MyConverter1 x:Key="MyConverter1"/>
</ContentView.Resources>
I will get a System.NullReferenceException from InitializeComponent(). Nothing in the stack trace or output window or anywhere else tells me what is wrong. Note: this syntax works fine in WPF.
After a lot of struggle I discovered I need this syntax...
<ContentView.Resources>
<ResourceDictionary>
<local:MyConverter1 x:Key="MyConverter1"/>
</ResourceDictionary>
</ContentView.Resources>
Likewise for ListView DataTemplate. This throws null reference exception...
<ListView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding Converter={StaticResource MyConverter1}}"/>
</DataTemplate>
</ListView.ItemTemplate>
Because the proper syntax is this...
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding Converter={StaticResource MyConverter1}}"/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
Again this syntax works fine in WPF. I fully realize that Xamarin Forms is not WPF but I getting weary of being sucker punched by null reference exceptions whenever I use a XAML construct that is valid in WPF.
What is the best way to debug Xamarin Forms XAML issues? Right now I am simply commenting stuff out until it starts working. This is akin to putting print statements in imperative code. Declarative code is supposed to be superior to imperative code. What am I doing wrong?
This throws null reference exception...- jdmdevdotnetxmlns:local="clr-namespace:{ProperNameSpace};assembly={ProperAssembly}". But again, can't speak really to much more until I understand what you mean by null reference - jdmdevdotnet