Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Cannot add multiple Labels in a form

$
0
0

Hi,

I have the following XAML which renders ok:

<ContentPage.Resources>
    <ResourceDictionary>
        <!-- This is only an issue on the iPhone; Android and 
       WinPhone auto size the row height to the contents. -->
        <OnPlatform x:Key="rowHeight" 
              x:TypeArguments="x:Int32"
              iOS="60"
              Android="60"
              WinPhone="85" />

    </ResourceDictionary>
</ContentPage.Resources>

<ContentPage.BindingContext>
    <!--<local:ViewModelLocator x:key="UsersViewModelStatic"/>-->
    <local:UsersViewModel/>
</ContentPage.BindingContext>

<ListView ItemsSource="{Binding Users}" RowHeight="{StaticResource rowHeight}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <ViewCell.View>
                    <StackLayout Padding="5, 0, 0, 0" VerticalOptions="Center">
                        <Label Text="{Binding FirstName}" Font="Bold, Medium" />
                    </StackLayout>
                </ViewCell.View>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

When I try to add another Label I get an error ("Object reference not set to an instance of an object."):

<ListView ItemsSource="{Binding Users}" RowHeight="{StaticResource rowHeight}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <ViewCell.View>
                    <StackLayout Padding="5, 0, 0, 0" VerticalOptions="Center">
                        <Label Text="{Binding FirstName}" Font="Bold, Medium" />
                        <Label Text="{Binding LastName}" Font="Bold, Medium" />
                    </StackLayout>
                </ViewCell.View>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

It doesn't matter whether the new label has binding or const text - the error is thrown either way.

Any ideas?

Thanks!


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>