我有一个 ListView 集,其中项目源作为子项。我想将一个子对象绑定(bind)到一个 View ,该 View 将通过转换器设置颜色。
调用了转换器方法,但我传入的值为 null
。
除了点,我还使用 Path=/
但传递给转换器的值仍然是 null
。如果我绑定(bind)属性,它很好,但不是当前项。
<ListView x:Name="childListView"
VerticalOptions="FillAndExpand"
HasUnevenRows="true"
ItemSelected="OnItemSelected"
ItemTapped="OnItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout
BackgroundColor="{Binding ., Converter={StaticResource accountedToColorConverter}}"
Spacing="0" Padding="0" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<StackLayout Orientation="Horizontal" Spacing="10" Padding="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<StackLayout Orientation="Horizontal" HorizontalOptions="StartAndExpand">
<controls:CircleImage>
最佳答案
这是一个有趣的行为。我最近在使用 CarouselView (Forms.Plugin)
时遇到了这个问题,并做了更多研究,结果发现每个 CarouselView
的 BindingContext
由于某种原因多次设置元素。
所以第一次,转换器获得了 null
值,但最终,它被第二次调用并得到了正确的值,所以我改变了我的转换器以优雅地处理 null
值(value)观,它奏效了。
关于xaml - Xamarin 窗体 : IValueConverter receive null value in Convert method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44103919/