user3452
user3452

Reputation: 359

How to set the perfect corner radius for the image inside a XfxCardView in xamarin forms?

I have a card view and in that, I have an image. I have to set the corner radius for that image so I'm using frames for doing that.

This is the UI I need and I have marked the Image

This is the result I'm getting .

This is my code

 <xfx:XfxCardView 
                        BackgroundColor="White"
                        CornerRadius="30" 
                    Elevation="30"
                 HeightRequest="100" >
                    <Grid RowSpacing="0">
                        <Grid ColumnSpacing="0">
                            <Grid.RowDefinitions >
                                <RowDefinition Height="*"></RowDefinition>

                                <RowDefinition Height="Auto"></RowDefinition>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions >
                                <ColumnDefinition Width="*"></ColumnDefinition>
                                <ColumnDefinition Width="Auto"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <Frame CornerRadius="10" Margin="0"  Padding="0" IsClippedToBounds="True">
                                <Image Margin="-70,0,0,0"   Source="restaurantimage1.jpg"  Grid.Row="0" Grid.Column="0" Grid.RowSpan="3"/>
                            </Frame>
                            <Label Grid.Row="0" Grid.Column="1" Margin="0,0,100,0" BackgroundColor="Aqua" HorizontalOptions="Start" Text="Premera restaurant" TextColor="Black" FontFamily="Bold,20"/>
                            <Label Grid.Row="1" Grid.Column="1" Margin="0,0,100,0" BackgroundColor="Green" HorizontalTextAlignment="Start" Text="Avenue Road,256" TextColor="Blue"/>
                            <Label Grid.Row="2" Grid.Column="1" Margin="0,0,100,0" BackgroundColor="LightBlue" VerticalTextAlignment="Start" Text="Indian,Italy,Chinese" TextColor="LightGray"/>
                        </Grid>
                    </Grid>
                </xfx:XfxCardView>

I have made changes in corner radius and margins but I'm not getting the desired result. Do I have to use something else to do that or should I make any changes in the Frame. I have done some changes in code so and I'm slightly near to the desired output. This is the current output

There is still a gap in the frame as you can see I have made changes in the code but still it is not getting fixed. This is my code

 <xfx:XfxCardView 
                        BackgroundColor="White"
                        CornerRadius="30" 
                    Elevation="30"
                 HeightRequest="100" >
                    <Grid RowSpacing="0">
                        <Grid ColumnSpacing="0">
                            <Grid.RowDefinitions >
                                <RowDefinition Height="*"></RowDefinition>

                                <RowDefinition Height="Auto"></RowDefinition>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions >
                                <ColumnDefinition Width="*"></ColumnDefinition>
                                <ColumnDefinition Width="Auto"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <Frame Margin="0" Padding="-40" CornerRadius="25" Grid.RowSpan="3"  BackgroundColor="LightBlue"  IsClippedToBounds="True">
                                <Image Margin="-70,0,0,0"  Grid.Row="0" Grid.Column="0" Grid.RowSpan="3"  BackgroundColor="AliceBlue"  Source="restaurantimage1.jpg"  />
                            </Frame>
                            <Label Grid.Row="0" Grid.Column="1" Margin="0,0,100,0"  HorizontalOptions="Start" Text="Premera restaurant" TextColor="Black" FontFamily="Bold,20"/>
                            <Label Grid.Row="1" Grid.Column="1" Margin="0,0,100,0"  HorizontalTextAlignment="Start" Text="Avenue Road,256" TextColor="Blue"/>
                            <Label Grid.Row="2" Grid.Column="1" Margin="0,0,100,0"  VerticalTextAlignment="Start" Text="Indian,Italy,Chinese" TextColor="LightGray"/>
                        </Grid>
                    </Grid>
                </xfx:XfxCardView>

Upvotes: 0

Views: 102

Answers (2)

user3452
user3452

Reputation: 359

I fixed it by changing the margin of my frame. This is my code now

 <xfx:XfxCardView 
                        BackgroundColor="White"
                        CornerRadius="30" 
                    Elevation="20"
                 HeightRequest="150" IsClippedToBounds="True">
                    <Grid RowSpacing="0" >
                        <Grid ColumnSpacing="0">
                            <Grid.RowDefinitions >
                                <RowDefinition Height="*"></RowDefinition>

                                <RowDefinition Height="Auto"></RowDefinition>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions >
                                <ColumnDefinition Width="*"></ColumnDefinition>
                                <ColumnDefinition Width="Auto"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <Frame Margin="10,10,10,20" Padding="-40" CornerRadius="10" Grid.RowSpan="3"  BackgroundColor="LightBlue"  IsClippedToBounds="True">
                                <Image Margin="-70,0,0,0"  Grid.Row="0" Grid.Column="0" Grid.RowSpan="3"  BackgroundColor="AliceBlue"  Source="restaurantimage1.jpg"  />
                            </Frame>
                            <Label Grid.Row="0" Grid.Column="1" Margin="0,30,30,0"  HorizontalOptions="Start" Text="Premera restaurant" TextColor="Black" FontFamily="Bold,20"/>
                            <Image Grid.Row="0" Grid.Column="1" Margin="0,30,10,0" HorizontalOptions="End" Source="whitehearticon3.jpg"/>
                            <Label Grid.Row="1" Grid.Column="1" Margin="0,-20,40,0"  HorizontalTextAlignment="Start" Text="Avenue Road,256" TextColor="Blue"/>
                            <Label Grid.Row="2" Grid.Column="1" Margin="0,0,40,0"  VerticalTextAlignment="Start" Text="Indian,Italy,Chinese Kitchen" TextColor="LightGray"/>


                        </Grid>
                    </Grid>
                </xfx:XfxCardView>

Upvotes: 0

FreakyAli
FreakyAli

Reputation: 16449

Try setting the is clipped to bounds property as true in your Grid's xaml

 <Grid RowSpacing="0" IsClippedToBounds="True">

Upvotes: 1

Related Questions