【问题标题】:Windows Phone 8.1 binding bing map pushpinsWindows Phone 8.1 绑定必应地图图钉
【发布时间】:2017-01-12 00:50:30
【问题描述】:

我想根据我的 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>

这里查看模型: 公共 ObservableCollection 用户 { 获取;放; }

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}
        }
    };
}

在启动程序时尝试显示地图图标时出现错误无论如何行中有错误

Title={绑定名称}

即使 User 模型具有属性 Name 并且我将 ItemSource 设置为 Users,它也无法解析 Name。

有人知道如何解决这个问题吗?

【问题讨论】:

    标签: c# xaml windows-phone-8.1 bing-maps


    【解决方案1】:

    在您的 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>
    

    指定您的 Observable 集合名称,即 Hairdressers 而不是 Users,因为您的集合名称是 Hairdressers

    public ObservableCollection Hairdressers { get; set; }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多