How to set margin around ImageCell in Xamarin.Forms?

mshwfmshwf EGMember

I want to have some space around the Image cell items of a ListView:

 <StackLayout>
        <ListView ItemsSource="{Binding Items}" HasUnevenRows="True">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ImageCell Text="{Binding Title}" ImageSource="{Binding Image}" TextColor="Black" DetailColor="Gray"/>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>

I tried the following:

    <DataTemplate>
           <StackLayout Padding="5">
               <ImageCell Text="{Binding Title}" ImageSource="{Binding Image}" TextColor="Black" DetailColor="Gray"/>
           </StackLayout>
    </DataTemplate>

but I got this exception in the OnCreate method in MainActivity.cs:

Unhandled Exception
System.InvalidCastException: Specified cast is not valid.

Furthermore, I need a 1 px border around the ImageCell, how can I have a control over it?

Best Answer

Answers

  • mshwfmshwf EGMember

    And how to define the margin property in the CustomImageCell?

  • VolodymyrSavchenkoVolodymyrSavchenko UAMember ✭✭✭

    I usually has scructure like RootView(StackLayout for example) => Grid(with margin, padding and all elements inside it). StackLayout shout take all space(FillAndExpand) and has transparent background. With Grid you can do whatever you want.

Sign In or Register to comment.