0
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を返します。バインディングラベルのテキストを保存します。これを達成するためにホ?あなたはIValueConverterバインディングコンテキストのラベル値をxamarinフォームの文字列に保存する方法
に
public class CustomVeggieCell : ViewCell
{
public CustomVeggieCell()
{
var image = new Image();
image.SetBinding(Image.SourceProperty, new Binding("contact", BindingMode.Default, new ConvertTextToSource()));
var horizontalLayout = new StackLayout();
horizontalLayout.Children.Add(image);
View = horizontalLayout;
}
}
のようなものを使用することができます
おかげで動作します必要があります:) – Jeni