Forum Xamarin.Forms

how add image/button next to last item in collection view in xamarin forms?

i need your help i'm trying to make the following UI in xamarin forms.i want the Upload button or image at the end of list . i tried to use collection view with grid item layout .i'm able to show images like this but i can't add upload image at the end like the following . i tried to put upload image/button in the footer of collection view but it appears in bottom of the list not in next to last image . So is there any body who can help me or guide me to achieve this?

Best Answer

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    Try to add a local image source at the last position of the items source to display this extra item after populating data:

    public ObservableCollection<string> Items { set; get; }
    public MainViewModel()
    {
        Items = new ObservableCollection<string>();
    
        // Add Data
        // Items.Add
    
        Items.Add("local image source");
    }
    

    Here is my simple template:

    <CollectionView ItemsSource="{Binding Items}">
        <CollectionView.ItemsLayout>
            <GridItemsLayout Orientation="Vertical" Span="4"/>
        </CollectionView.ItemsLayout>
        <CollectionView.ItemTemplate>
            <DataTemplate>
                <StackLayout>
                    <Image Source="{Binding}"/>
                </StackLayout>
            </DataTemplate>
        </CollectionView.ItemTemplate>
    </CollectionView>
    

    My point here is to display an extra cell with a local image at the last of the collection view.

  • ProgrammerProgrammer Member ✭✭

    @LandLu i tried this

            public ObservableCollection<ImageSource> Items { set; get; }
            public MainViewModel()
            {
                Items = new ObservableCollection<ImageSource>();
            // Add Data
                // Items.Add
            Items.Add("local image source");
            }
    

    and i got this out put ,the local image is not adding at the end .

  • ProgrammerProgrammer Member ✭✭

    @LandLu Thank you so much

Sign In or Register to comment.