Can't get the CollectionView to Display data in my collection

Viewed 22

I am trying to make a collectionView display the items in a collection I have created but that doe snot work at all. I have been looking around to understand the issue but I can't figure it out. Can someone help me out ? See below the XAML code for a custom control I created and following it the code behind in c#

'''

<StackLayout xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="CustomControls.CustomControl.DataGrid2"
             xmlns:local="clr-namespace:CustomControls.CustomControl"
             HeightRequest="500"
             WidthRequest="500"
             Orientation="Horizontal">

     <CollectionView x:Name="c2" ItemsLayout="VerticalList" x:DataType="local:DataGrid2" ItemsSource="{Binding Data2see}" >
      <CollectionView.Header>
        <StackLayout BackgroundColor="LightGray">
            <Label Margin="10,0,0,0"
                   Text="Monkeys"
                   FontSize="Small"
                   FontAttributes="Bold" />
        </StackLayout>
    </CollectionView.Header>
    <CollectionView.Footer>
        <StackLayout BackgroundColor="LightGray">
            <Label Margin="10,0,0,0"
                   Text="Friends of Xamarin Monkey"
                   FontSize="Small"
                   FontAttributes="Bold" />
        </StackLayout>
    </CollectionView.Footer>
        <CollectionView.ItemTemplate>
            <DataTemplate x:DataType="local:SomeDataExemple2">
                <Grid Padding="10" ColumnDefinitions="100,100,100">
                    <Button Grid.Column="0" Text ="clickmenow2"/>
                    <Entry Grid.Column= "1" Text="{Binding Name}"/>
                    <Entry Grid.Column="2" Text="{Binding First_name}"/>
                </Grid>
            </DataTemplate>
        </CollectionView.ItemTemplate>
    </CollectionView>
</StackLayout>


    namespace CustomControls.CustomControl
    { using System.Collections.Specialized;
    using System.Collections.Generic;
    using System.Collections;
    using System.Collections.ObjectModel;
 

    public partial class DataGrid2 : StackLayout
    {
        public DataGrid2()
        {
            Data2see = new Collection<SomeDataExemple2>();
            Data2see.Add(new SomeDataExemple2("hamid", "britel"));
            Data2see.Add(new SomeDataExemple2("mernissi", "wadie"));
            Data2see.Add(new SomeDataExemple2("mhamed", "chraibi"));
            Data2see.Add(new SomeDataExemple2("yazid", "alaoui"));
            Data2see.Add(new SomeDataExemple2("amine", "gogole"));
            Data2see.Add(new SomeDataExemple2("mehdi", "harras"));

            InitializeComponent();
            //c2.ItemsSource = Data;
        }

        public Collection<SomeDataExemple2> Data2see
        {
            get;
            set;
        }
    }

    public class SomeDataExemple2
    {

        public SomeDataExemple2(string name1, string name2)
        {
            Name = name1;
            First_name = name2;
        }

        public string Name
        {
            get; set;
        }


        public string First_name
        {
            get;
            set;
        }
    }}
0 Answers
Related