<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:pageModels="clr-namespace:MauiBrokenBindings.PageModels"
             xmlns:models="clr-namespace:MauiBrokenBindings.Models"
             xmlns:controls="clr-namespace:MauiBrokenBindings.Pages.Controls"
             xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
             x:Class="MauiBrokenBindings.Pages.ProjectListPage"
             x:Name="ProjectList"
             x:DataType="pageModels:ProjectListPageModel"
             Title="Projects">


    <ContentPage.Behaviors>
        <toolkit:EventToCommandBehavior
                x:Name="AppearingBehavior"
                BindingContext="{Binding Path=BindingContext, Source={x:Reference ProjectList}, x:DataType=ContentPage}"
                EventName="Appearing"                
                Command="{Binding AppearingCommand}" />
    </ContentPage.Behaviors>
    <Grid>
        <CollectionView ItemsSource="{Binding Projects}"
            Margin="{StaticResource LayoutPadding}"
            x:Name="ProjectsCollectionView"
            SelectionMode="Single"
            SelectedItem="{Binding SelectedProject}"
            SelectionChangedCommand="{Binding NavigateToProjectCommand, Source={RelativeSource AncestorType={x:Type pageModels:ProjectListPageModel}}, x:DataType=pageModels:ProjectListPageModel}"
            SelectionChangedCommandParameter="{Binding SelectedProject}">
            <CollectionView.ItemsLayout>
                <LinearItemsLayout Orientation="Vertical" ItemSpacing="7.5"/>
            </CollectionView.ItemsLayout>
            <CollectionView.ItemTemplate>
                <DataTemplate x:DataType="models:Project">
                    <Border SemanticProperties.Description="{Binding Name, StringFormat='{0}'}">
                        <VerticalStackLayout Padding="10">
                            <Label Text="{Binding Name}" FontSize="24" />
                            <Label Text="{Binding Description}" />
                        </VerticalStackLayout>
                    </Border>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>

        <controls:AddButton
        Command="{Binding AddProjectCommand}" />
    </Grid>
</ContentPage>