Forum Cross Platform with Xamarin

Why my dataGrid is empty?

<?xml version="1.0" encoding="utf-8" ?>

<ContentPage.Content>

                <Label  Text="NumBc" VerticalOptions="Center" Grid.Column="0" />
                <Label Text="CustomersName" VerticalOptions="Center" Grid.Column="1" />
                <Label Text="Adress" VerticalOptions="Center" Grid.Column="2"/>

                <BoxView BackgroundColor="DarkSlateGray" WidthRequest="1" Grid.Column="0" HorizontalOptions="EndAndExpand" VerticalOptions="FillAndExpand"/>
                 <BoxView BackgroundColor="DarkSlateGray" WidthRequest="1" Grid.Column="1" HorizontalOptions="EndAndExpand" VerticalOptions="FillAndExpand"/>
                 <BoxView BackgroundColor="DarkSlateGray" WidthRequest="1" Grid.Column="2" HorizontalOptions="EndAndExpand" VerticalOptions="FillAndExpand"/>
            </Grid>
        </Frame>
        <ListView ItemsSource="{Binding BCs}" SeparatorVisibility="Default" SelectionMode="None">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Frame Padding="0">
                            <Grid Padding="0">
                               <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>

                                <Label Text="{Binding NumBC}" VerticalOptions="Center" Grid.Column="0" />
                                <Label Text="{Binding CustomerName}" VerticalOptions="Center" Grid.Column="1" />
                                <Label  Text="{Binding Adress}" VerticalOptions="Center" Grid.Column="2" />

                            </Grid>
                        </Frame>


                    </ViewCell>
                </DataTemplate> 
            </ListView.ItemTemplate>
        </ListView>
        <StackLayout >
            <Button Text="Update"/>
            <Button Text="Delete"/>
            <Button Text="Imprimer"/>
        </StackLayout>
    </StackLayout>

</ContentPage.Content>


namespace BC
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class BCpage : ContentPage
{
public BCpage ()
{
InitializeComponent ();
BindingContext = new BCViewModel();

    }
}

}
namespace BC
{
public class BCViewModel : INotifyPropertyChanged
{
public ObservableCollection BCs { get; set; }

    public BCViewModel()
    {
        BCs = new ObservableCollection<BC>

        {
            new BC() { NumBc="Num BC1", CustomerName="Bkonsult", Adress="Manzeh 6" },
            new BC() { NumBc="Num BC2", CustomerName="Bkonsult", Adress="Manzeh 6" },
            new BC() { NumBc="Num BC3", CustomerName="Bkonsult", Adress="Manzeh 6" },
            new BC() { NumBc="Num BC4", CustomerName="Bkonsult", Adress="Manzeh 6" },
            new BC() { NumBc="Num BC5", CustomerName="Bkonsult", Adress="Manzeh 6" } };
    }           


    public event PropertyChangedEventHandler PropertyChanged;
    private void OnPropertyChanged([CallerMemberName] string propertyName = "")
    {
        if (PropertyChanged == null)
            return;

        PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

}

}
namespace BC
{
public class BC
{
public string CustomerName { get; set; }
public string Adress { get; set; }
public string NumBc { get; set; }
}
}
namespace BC
{
public partial class App : Application
{
public App()
{
InitializeComponent();

        MainPage = new BCpage();
    }
Tagged:

Best Answers

Answers

  • RaniaMKRaniaMK Member ✭✭

    thank you

Sign In or Register to comment.