【问题标题】:Xamarin forms - Dynamically-bound image in CarouselView lost Aspect.Fit after image change on AndroidXamarin 表单 - 在 Android 上更改图像后,CarouselView 中的动态绑定图像丢失了 Aspect.Fit
【发布时间】:2020-01-30 00:45:47
【问题描述】:

我正在开发一个使用 Xamarin 表单的跨平台项目。我正在使用 carouselview 来显示图像按钮。请参阅下面的代码 sn-ps。 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

【问题讨论】:

  • ,我做了一个关于 CarouselViewControl 的示例,但我无法重现您的问题。您如何更改图像?你能在这里提供一些关于你的问题的截图吗?你能在 github 上提供一个可以重现你的问题的示例,我会下载你的示例进行测试。
  • 嗨樱桃,谢谢。我从 C# 中另一个页面的视图模型更改图像。请在github中找到随附的屏幕截图..
  • 从 CustomImageButton 更改为 ImageButton 没有区别。方面匹配问题仍然存在。

标签: xamarin.forms imagebutton aspect-fit


【解决方案1】:

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

【讨论】:

  • ,很高兴听到你自己解决了你的问题,如果你认为是xamarin.forms的问题,我建议你可以在github上反馈这个问题,请记住将你的回复标记为答案关闭你的线程,谢谢。
猜你喜欢
  • 2017-09-06
  • 2020-03-12
  • 1970-01-01
  • 2019-08-17
  • 2018-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-18
相关资源
最近更新 更多