0

我正在使用 Xamarin 表单进行跨平台项目。我正在使用 carouselview 来显示图像按钮。请参阅下面的代码片段。customImageButtonStyle 设置为 Aspect.Aspect.Fit。最初它按预期工作。但是,图像更改后,图像仍然显示,但更小,即。不再做 Aspect.Fit。如果我将相同的代码放在轮播视图之外,它就不会出现这样的问题。

    <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>

请注意,此问题也记录在https://github.com/alexrainman/CarouselView/issues/561

4

1 回答 1

0

看来这是一个 Xamarin 表单问题。我试图用图像替换图像按钮,问题就消失了。当绑定图像从视图模型更改时,有时 AspectFit 似乎不适用于 ImageButton。

于 2020-01-30T07:38:59.017 回答