【发布时间】:2017-10-21 13:59:55
【问题描述】:
我有一个将项目源设置为子项的列表视图。我想将一个子对象绑定到一个视图,该视图将通过转换器设置颜色。
转换器方法被调用,但我传入的值是null。
除了点,我还使用Path=/,但传递给转换器的值仍然是null。如果我绑定属性,那很好,但不是当前项。
<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>
【问题讨论】:
-
什么是“。”意味着在您的代码中
BackgroundColor属性的绑定中?如果您显示此 XAML 背后的代码,可能会更容易找到 -
在 XAML 中,值转换器通常在
ResourceDictionary中实例化,然后使用StaticResource标记扩展在绑定表达式中引用。请提供相关代码以获得帮助。 -
“.”我用在我的其他代码中,我在列表中有一个组绑定,在那个组中,我有字符串和其他对象组。这 ”。”表示列表中的当前项。我在模板选择器中使用了它,而不是在 IValueConverter 上使用它。
标签: xaml xamarin binding converter