【发布时间】:2017-08-17 05:07:26
【问题描述】:
ListView listView = new ListView();
listView.ItemTemplate = new DataTemplate(typeof(CustomVeggieCell));
listView.ItemsSource = sample;
Content = new StackLayout
{
Children ={
listView,
}
};
public class CustomVeggieCell : ViewCell
{
public CustomVeggieCell()
{
var image = new Image();
var typeLabel = new Label { };
typeLabel.SetBinding(Label.TextProperty, new Binding("contact"));
var string = typeLabel.Text;
if (typeLabel.Text == "Send")
{
image.Source = "Send.png";
}
else
{
image.Source = "draft.png";
}
var horizontalLayout = new StackLayout();
horizontalLayout.Children.Add(image);
View = horizontalLayout;
}
}
我在 Xamarin 表单中创建了一个带有 Json Web 服务响应的列表视图。我需要根据值显示图像。 绑定值不能存储在字符串中。它总是返回 null。我想存储绑定标签文本。何能做到这一点?
【问题讨论】:
标签: listview xamarin binding xamarin.forms label