0

I am working on a cross-platform project using Xamarin forms. I am using carouselview to display an image button. See the code snippets below. The customImageButtonStyle sets to Aspect.Aspect.Fit. Initially it works as intended. However, after the image is changed, the image is still displayed, but smaller, ie. no longer does Aspect.Fit. If I place the same code outside the carouselview, it works without such a issue.

    <StackLayout Grid.Row="0" Grid.Column="1" Orientation="Vertical" HorizontalOptions="CenterAndExpand">
                <Grid x:Name="relayGrid" HorizontalOptions="CenterAndExpand">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="4.0*" />
                        <RowDefinition Height="1*" />
                    </Grid.RowDefinitions>
                    <views:CustomImageButton x:Name="relayButton" Source="{Binding RelayIcon}" Grid.Row="0" Grid.Column="0" 
                                             Style="{StaticResource customImageButtonStyle}"
                                             Command="{Binding NavigateCommand}" CommandParameter="{x:Type views:RelayPage}" />
                    <Label Text="RELAYS" Grid.Row="1" Grid.Column="0" Style="{StaticResource deviceHomeBottomTextStyle}" />
                </Grid>
                <StackLayout.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding NavigateCommand}" CommandParameter="{x:Type views:RelayPage}" />
                </StackLayout.GestureRecognizers>
            </StackLayout>
        </Grid>
    </x:Array>
</controls:CarouselViewControl.ItemsSource>

Please note this issue is also logged at https://github.com/alexrainman/CarouselView/issues/561

Hong Wang
  • 65
  • 10
  • ,I do one sample about CarouselViewControl, but I can not reproduce your issue.How do you change image? Can you provide some screenshot about your issue here?Can you provide one sample at github that can reproduce your issue, I will download your sample to test. – Cherry Bu - MSFT Jan 30 '20 at 03:31
  • Hi Cherry, Thank you. I change the image from the view model of another page in C#. Please find the attached screenshot in github.. – Hong Wang Jan 30 '20 at 03:51
  • Changing to ImageButton from CustomImageButton makes no difference. The aspect fit issue remains. – Hong Wang Jan 30 '20 at 04:07

1 Answers1

0

It seems this is a Xamarin forms issue. I've tried to replace the image button with an image, the problem goes away. It seems sometimes AspectFit doesn't work for ImageButton when the bound image changes from a view model.

Hong Wang
  • 65
  • 10
  • ,Glad to hear that you have solved your issue by yourself,if you think it is xamarin.forms issue, I suggest you can feedback this issue at github,please remember to mark your reply as answer to close your thread, thanks. – Cherry Bu - MSFT Feb 03 '20 at 06:38