Skip to content

App crash if Binding is null #28

Description

@ChrisProlls

I have a ListView binded to a list of MenuItem

    public class MenuItem
    {
        public string Icon { get; set; }
        public string Title { get; set; }
        public string Page { get; set; }
    }
public ObservableCollection<BeloteMenuItem> _menuItems = new ObservableCollection<BeloteMenuItem>(
            new[]
            {
                new BeloteMenuItem { Icon = "fa-home"  },
                new BeloteMenuItem { Icon = null }
            });
<ListView x:Name="MenuItemsListView"
              SeparatorVisibility="None"
              HasUnevenRows="true"
              ItemsSource="{Binding MenuItems}">
        <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Padding="15,10" HorizontalOptions="FillAndExpand">
                            <iconize:IconImage HeightRequest="20" Icon="{Binding Icon}" IconColor="Black" WidthRequest="20" />
                            <Label VerticalOptions="FillAndExpand" 
                                VerticalTextAlignment="Center" 
                                Text="{Binding Title}"
                                FontSize="17"/>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
</ListView>

In my example I volontary set one of my icon to null and the app immediately crashes, an the Xamarin.Forms error is not very convenient to debug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions