xamarin.forms - Xamarin 映射 observablecollection 不更新视图
问题描述
感谢Bind to Xamarin.Forms.Maps.Map from ViewModel我制作了一个自定义地图。但是当我从视图模型中添加引脚时,我在视图中看不到它们。
<maps:BindableMap MapSpan="{Binding MapSpan}" PinsSource="{Binding Pins}"/>
和视图模型代码
public ObservableCollection<Pin> Pins
{
get
{
return _pins;
}
set
{
_pins = value;
}
}
Pins.Add(new Pin { Address=address, Position =position, Label=label, Type=type});
还是看不到别针。。
解决方案
不要在非官方文件上做自定义地图。转到官方网站: https ://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/map-pin
和自定义渲染器(取决于你想要做什么) https://docs.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/customrenderers-map-pin/
然后按照 StackOverflow 问题进行操作。也不要将一半的代码放在 xaml 中,一半放在 C# 中,这只会使你的代码变得复杂,放置 c# 替代方案或 xaml 替代方案。不要将两者混合。它只会产生错误、错误或混乱。
和自定义地图:
public class CustomMap : Map
{
public ObservableCollection<CustomPin> CustomPins { get; set; }
}
应该这样做。
推荐阅读
- python - ImportError:没有名为 werkzeug.utils 的模块
- node.js - 卡在从 AWS S3 检索图像
- c++ - 如何理解“包含省略号的抽象声明符只能用于参数声明”
- json - 是否有用于过滤 json 数据的 JsonPatch 模拟?
- machine-learning - 理解稀疏自动编码器背后的逻辑
- java - 打开的游标过多
- api - 将路径参数与查询参数混合以获取静态请求?
- python - 如何通过单击 matplotlib 中的图例条目来突出显示点?
- php - PHP array_reduce():得到一个错误“无效的函数名”
- spring - @RequestBody 获取参数值 null