【发布时间】:2018-05-28 12:57:43
【问题描述】:
您好,我已经在 google 上运行了每个链接,但我似乎无法找到解决我的 2 个问题的方法。
我正在为 Xamarin 表单中的 android 和 IOS 构建 n 应用程序,我想要一个包含文本和图像的列表,就像这个例子一样。
问题是: [更新] 1. 无法让文字显示坐标。 2. 我无法替换所选项目上丑陋的橙色
像这样:[更新]
这是我的代码:
主页
private ObservableCollection<Store> stores { get; set; }
public MainPage()
{
InitializeComponent();
storesList.BackgroundColor = Color.CornflowerBlue;
storesList.SeparatorColor=Color.White;
storesList.ItemTemplate = new DataTemplate(typeof(StoreCell));
stores = new ObservableCollection<Store>();
Store store1 = new Store
{
Name = "Pombal",
Location = new Coordinate(39.9143958, -8.6297282).ToString()
};
Store store2 = new Store
{
Name = "Unknown",
Location = new Coordinate(8.9143958, -39.6297282).ToString(),
Schedule = "09:00-12:30 / 13:30-18:00"
};
stores.Add(store1);
stores.Add(store2);
storesList.ItemsSource = stores;
}
<ListView x:Name="storesList" RowHeight="70" HasUnevenRows="True">
</ListView>
存储单元
public StoreCell()
{
InitializeComponent();
var image = new Image();
var nameLabel = new Label { TextColor = Color.White };
var locationLabel = new Label { TextColor = Color.White };
var scheduleLabel = new Label { TextColor = Color.White };
var verticaLayout = new StackLayout();
var horizontalLayout = new StackLayout();
//set bindings
nameLabel.SetBinding(Label.TextProperty, new Binding("Name"));
locationLabel.SetBinding(Label.TextProperty, new Binding("Location"));
scheduleLabel.SetBinding(Label.TextProperty, new Binding("Schedule"));
image.SetBinding(Image.SourceProperty, new Binding("Image"));
//Set properties for desired design
horizontalLayout.Orientation = StackOrientation.Horizontal;
horizontalLayout.HorizontalOptions = LayoutOptions.Fill;
image.HorizontalOptions = LayoutOptions.End;
nameLabel.FontSize = 24;
//add views to the view hierarchy
verticaLayout.Children.Add(nameLabel);
verticaLayout.Children.Add(locationLabel);
verticaLayout.Children.Add(scheduleLabel);
horizontalLayout.Children.Add(verticaLayout);
horizontalLayout.Children.Add(image);
// add to parent view
View = horizontalLayout;
}
[更新]
坐标类 toString
public override string ToString()
{
return X + " , " + Y;
}
商店类
可能做错了......
class Store
{
public string Name { get; set; }
public string Location { get; set; }
public string Schedule { get; set; }
public Store() : this(null, null, null)
{
}
public Store(String name, string location) : this(name, location, "")
{
}
public Store(String name, string location, String schedule)
{
Name = name;
Location = location;
Schedule = schedule;
}
}
有什么需要的直接问吧,非常感谢。
【问题讨论】:
标签: listview xamarin.forms multiline listviewitem selecteditem