charitht99 perera
charitht99 perera

Reputation: 325

Nothing Show inside Stacklayout

I' m working in Xamarin forms application ,I'm currently implementing a form contains two parts one is data entering part and other part is a list view Afetr i entered data and saved it should appear in list view ,In debug i checked ListViewUsers.ItemsSource count is not 0 it has values , but listView is not showing in the form .

 <ContentPage.Content>
        <StackLayout>
            <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="500"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
             <StackLayout Grid.Row="0" Grid.Column="0">
            <Grid x:Name="grid">
                <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
             </Grid.ColumnDefinitions>
                <Label x:Name="labelName" Grid.Row="0"  Grid.Column="0" Margin="10" FontSize="6"  VerticalOptions="CenterAndExpand"  HorizontalTextAlignment="Start" Text="Name"/>
                <Entry  x:Name="textName" Grid.Row="0"  Grid.Column="1"  WidthRequest="100" FontSize="6" VerticalOptions="CenterAndExpand" HorizontalOptions="Start" HorizontalTextAlignment="Start" Text="{Binding Name}"  />
                <Label x:Name="labelAge" Grid.Row="1"  Grid.Column="0" Margin="10" FontSize="6"  Text="Age" VerticalOptions="CenterAndExpand" HorizontalTextAlignment="Start" />
                <Entry  x:Name="textAge" Grid.Row="1"  Grid.Column="1" WidthRequest="100" FontSize="6" VerticalOptions="CenterAndExpand" HorizontalOptions="Start" HorizontalTextAlignment="Start" Text="{Binding Age}" />
                <Label x:Name="labelAddress" Grid.Row="2"  Grid.Column="0" Margin="10" FontSize="6"  Text="Address" VerticalOptions="CenterAndExpand" HorizontalTextAlignment="Start" />
                <Entry  x:Name="textAddress" Grid.Row="2"  Grid.Column="1" WidthRequest="100" FontSize="6" VerticalOptions="CenterAndExpand" HorizontalOptions="Start" HorizontalTextAlignment="Start"  Text="{Binding Address}" />
                <Label x:Name="labelNICNumber" Grid.Row="3"  Grid.Column="0" Margin="10" FontSize="6" Text="NIC" VerticalOptions="CenterAndExpand" HorizontalTextAlignment="Start" />
                <Entry  x:Name="textNIC" Grid.Row="3"  Grid.Column="1" WidthRequest="100" FontSize="6" VerticalOptions="CenterAndExpand" HorizontalOptions="Start" HorizontalTextAlignment="Start" Text="{Binding NIC}" />
                <Button Grid.Row="4"  Grid.Column="1" HeightRequest = "30"   VerticalOptions="CenterAndExpand" HorizontalOptions="Start" FontSize="6" Text="Save" Clicked="UserSaveClick" />
            </Grid>
        </StackLayout>
        <StackLayout Grid.Row="1"  Grid.Column="0">
                    <Label x:Name="labelNICNumber2" Grid.Row="3"  Grid.Column="0" Margin="10" FontSize="6" Text="NIC" VerticalOptions="CenterAndExpand" HorizontalTextAlignment="Start" />
                    <ListView x:Name="ListViewUsers" SeparatorColor="Transparent"  HasUnevenRows="True" IsVisible="True" IsEnabled="True">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="1*" />
                                        <ColumnDefinition Width="2*" />
                                        <ColumnDefinition Width="3*" />
                                        <ColumnDefinition Width="4*" />
                                    </Grid.ColumnDefinitions>



                                    <Label 
                                    WidthRequest="20"
                                    HeightRequest="15"
                                    TextColor="Black"
                                    FontFamily="Open Sans"
                                    FontSize="6"          
                                    Text="{Binding Name}"
                                    VerticalOptions="Center"
                                    HorizontalOptions="Start"
                                    Grid.Column="1"/>

                                    <Label 
                                    WidthRequest="20"
                                    HeightRequest="15"
                                    TextColor="Black"
                                    FontFamily="Open Sans"
                                    FontSize="10"          
                                    Text="{Binding Age}"
                                    VerticalOptions="Center"
                                    HorizontalOptions="Start"
                                    Grid.Column="2" />

                                     <Label 
                                    WidthRequest="20"
                                    HeightRequest="15"
                                    TextColor="Black"
                                    FontFamily="Open Sans"
                                    FontSize="10"          
                                    Text="{Binding Address}"
                                    VerticalOptions="Center"
                                    HorizontalOptions="Start"
                                     Grid.Column="3" />


                                    <Label 
                                    WidthRequest="20"
                                    HeightRequest="15"
                                    TextColor="Black"
                                    FontFamily="Open Sans"
                                    FontSize="10"          
                                    Text="{Binding NIC}"
                                    VerticalOptions="Center"
                                    HorizontalOptions="Start"
                                    Grid.Column="4"/>
                                </Grid>

                            </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </StackLayout>
        </Grid>
     </StackLayout>

Upvotes: 0

Views: 207

Answers (1)

TheGeneral
TheGeneral

Reputation: 81493

Its hard to see whats going on here, however

  • I have removed the redundant column definition
  • I have removed the highest level stacklayout, and just used a grid
  • I have removed the second nested stacklayout and left the grid
  • I have set both Rows to * in the main grid, just to make sure

Note : if this doesn't work, remove everything except the ListView, just as a sanity check

Xaml

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <Grid x:Name="grid" Grid.Row="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Label
            x:Name="labelName"
            Grid.Row="0"
            Grid.Column="0"
            Margin="10"
            FontSize="6"
            HorizontalTextAlignment="Start"
            Text="Name"
            VerticalOptions="CenterAndExpand" />
        <Entry
            x:Name="textName"
            Grid.Row="0"
            Grid.Column="1"
            FontSize="6"
            HorizontalOptions="Start"
            HorizontalTextAlignment="Start"
            Text="{Binding Name}"
            VerticalOptions="CenterAndExpand"
            WidthRequest="100" />
        <Label
            x:Name="labelAge"
            Grid.Row="1"
            Grid.Column="0"
            Margin="10"
            FontSize="6"
            HorizontalTextAlignment="Start"
            Text="Age"
            VerticalOptions="CenterAndExpand" />
        <Entry
            x:Name="textAge"
            Grid.Row="1"
            Grid.Column="1"
            FontSize="6"
            HorizontalOptions="Start"
            HorizontalTextAlignment="Start"
            Text="{Binding Age}"
            VerticalOptions="CenterAndExpand"
            WidthRequest="100" />
        <Label
            x:Name="labelAddress"
            Grid.Row="2"
            Grid.Column="0"
            Margin="10"
            FontSize="6"
            HorizontalTextAlignment="Start"
            Text="Address"
            VerticalOptions="CenterAndExpand" />
        <Entry
            x:Name="textAddress"
            Grid.Row="2"
            Grid.Column="1"
            FontSize="6"
            HorizontalOptions="Start"
            HorizontalTextAlignment="Start"
            Text="{Binding Address}"
            VerticalOptions="CenterAndExpand"
            WidthRequest="100" />
        <Label
            x:Name="labelNICNumber"
            Grid.Row="3"
            Grid.Column="0"
            Margin="10"
            FontSize="6"
            HorizontalTextAlignment="Start"
            Text="NIC"
            VerticalOptions="CenterAndExpand" />
        <Entry
            x:Name="textNIC"
            Grid.Row="3"
            Grid.Column="1"
            FontSize="6"
            HorizontalOptions="Start"
            HorizontalTextAlignment="Start"
            Text="{Binding NIC}"
            VerticalOptions="CenterAndExpand"
            WidthRequest="100" />
        <Button
            Grid.Row="4"
            Grid.Column="1"
            Clicked="UserSaveClick"
            FontSize="6"
            HeightRequest="30"
            HorizontalOptions="Start"
            Text="Save"
            VerticalOptions="CenterAndExpand" />
    </Grid>

    <StackLayout Grid.Row="1">
        <Label
            x:Name="labelNICNumber2"
            Grid.Row="3"
            Grid.Column="0"
            Margin="10"
            FontSize="6"
            HorizontalTextAlignment="Start"
            Text="NIC"
            VerticalOptions="CenterAndExpand" />
        <ListView
            x:Name="ListViewUsers"
            HasUnevenRows="True"
            IsEnabled="True"
            IsVisible="True"
            SeparatorColor="Transparent">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="1*" />
                                <ColumnDefinition Width="2*" />
                                <ColumnDefinition Width="3*" />
                                <ColumnDefinition Width="4*" />
                            </Grid.ColumnDefinitions>



                            <Label
                                Grid.Column="1"
                                FontFamily="Open Sans"
                                FontSize="6"
                                HeightRequest="15"
                                HorizontalOptions="Start"
                                Text="{Binding Name}"
                                TextColor="Black"
                                VerticalOptions="Center"
                                WidthRequest="20" />

                            <Label
                                Grid.Column="2"
                                FontFamily="Open Sans"
                                FontSize="10"
                                HeightRequest="15"
                                HorizontalOptions="Start"
                                Text="{Binding Age}"
                                TextColor="Black"
                                VerticalOptions="Center"
                                WidthRequest="20" />

                            <Label
                                Grid.Column="3"
                                FontFamily="Open Sans"
                                FontSize="10"
                                HeightRequest="15"
                                HorizontalOptions="Start"
                                Text="{Binding Address}"
                                TextColor="Black"
                                VerticalOptions="Center"
                                WidthRequest="20" />


                            <Label
                                Grid.Column="4"
                                FontFamily="Open Sans"
                                FontSize="10"
                                HeightRequest="15"
                                HorizontalOptions="Start"
                                Text="{Binding NIC}"
                                TextColor="Black"
                                VerticalOptions="Center"
                                WidthRequest="20" />
                        </Grid>

                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</Grid>

Upvotes: 1

Related Questions