image - Xamarin Binding 函数作为具有数据绑定的 Listview 中的 ImageSource
问题描述
我试图MinRepresentation
在下面的 ListView 中可视化一个名为 的对象的状态。
我想绑定函数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");
}
}
解决方案
您只能绑定到公共属性。在模型上创建 StateImage 属性
public string StateImage
{
get {
switch (State)
{
case MinRepresentationState.Assigned:
return "state_assigned.png";
}
}
}
推荐阅读
- javascript - 如何在nodejs中的foreach中获取价值
- php - 使用 codeigniter 查询选择属性设置为 null 的字段
- python - 启动 Spyder 内核时发生错误
- c++ - 如何在 Dev-c++ 中安装外部库?(雷库)
- function - Google 表格的 IMPORTHTML() 未能保持数据的原始格式
- angular - 如何将新数据附加到存储在 firebase 的 firestore 上的数组中?节点,Ionic3,角度,Javascript
- python - 存储函数的参数以供以后评估
- r - 在 r 中创建特殊的子组列
- c# - 无法访问文件夹名称末尾有多个连续空格的文件
- azure-data-factory - REST 成功,Azure 数据工厂中的 HTTP 失败,但需要证书