[英]Windows Phone 8.1 binding bing map pushpins
我想根據我的ObservableCollection顯示圖釘:
XAML:
<Grid>
<my:MapControl>
<my:MapItemsControl ItemsSource="{Binding Users}">
<my:MapItemsControl.ItemTemplate>
<DataTemplate>
<my:MapIcon Title="{Binding Name}" Location="{Binding Location}"></my:MapIcon>
</DataTemplate>
</my:MapItemsControl.ItemTemplate>
</my:MapItemsControl>
</my:MapControl>
</Grid>
這里是ViewModel:public ObservableCollection Users { 組; }
public MapPageViewModel()
{
Users = new ObservableCollection<User>()
{
new User
{
Id = 1,
Name = "Chris",
Location = new Location { Latitude = 52.645, Longitude = 13.431}
},
new User
{
Id = 1,
Name = "Brown",
Location = new Location { Latitude = 52.15, Longitude = 12.431}
}
};
}
無論如何,啟動程序時嘗試顯示地圖圖標時都會出錯
標題= {綁定名稱}
即使用戶模型具有屬性名稱,並且我將ItemSource設置為用戶,它也無法解析名稱。
有誰知道如何解決這個問題?
在您的xaml中使用此代碼
<Grid>
<my:MapControl>
<my:MapItemsControl ItemsSource="{Binding Hairdressers}">
<my:MapItemsControl.ItemTemplate>
<DataTemplate>
<my:MapIcon Title="{Binding Name}" Location="{Binding Location}"></my:MapIcon>
</DataTemplate>
</my:MapItemsControl.ItemTemplate>
</my:MapItemsControl>
</my:MapControl>
</Grid>
指定您的可觀察集合名稱,即Hairdressers而不是Users,因為您的集合名稱為Hairdressers :
public ObservableCollection Hairdressers { get; set; }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.