【发布时间】:2019-10-19 00:40:12
【问题描述】:
我正在尝试在下面的 ListView 中可视化一个名为 MinRepresentation 的对象的状态。
我想绑定函数ImageSource stateImage(MinRepresentationState state),在这里我切换状态并取回Imagesource。
我的问题是,访问函数并通过 xaml 传递参数。
Visible Orders 是 MinRepresentation 的集合,每个都包含 State
<ListView HasUnevenRows="True" SelectionMode="Single" ItemsSource="{Binding VisibleOrders}" ItemSelected="OnListViewItemSelected" ItemTapped="OnListViewItemTapped">
***OTHER STUFF***
<StackLayout Orientation="Horizontal" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" Padding= "0,5,0,5" BackgroundColor="#CC3F6E3F">
<Image Source="{Binding stateImage(State)" Margin="10,0,0,0" />
<Label Text="{Binding Id, StringFormat='ID: [{0}]'}" FontSize="Small" Margin="5,0,0,0" FontAttributes="Bold" TextColor="#FFFFFF"/>
</StackLayout>
***OTHER STUFF***
</ListView>
public ImageSource stateImage(MinRepresentationState state)
{
switch (state)
{
case MinRepresentationState.Assigned:
return ImageSource.FromResource("state_assigned.png");
}
}
【问题讨论】:
-
只能绑定公共属性,不能绑定方法
-
知道如何解决这个问题吗?
标签: image listview xamarin binding