点击图钉后,我需要在地图上添加一个按钮。我将xamarin表单和googlemaps用于iOS和Android。
这是我的XAML:
<AbsoluteLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<ContentView Content="{Binding Map}" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" AbsoluteLayout.LayoutBounds = "1, 1, 1, 1" AbsoluteLayout.LayoutFlags = "All"/>
<Button BackgroundColor="White" IsVisible="{Binding IsPinVisible}" Text="{Binding NewAddress}" TextColor="Blue" AbsoluteLayout.LayoutBounds = "1, 0, 1, 0.15" AbsoluteLayout.LayoutFlags = "All"/>
</AbsoluteLayout>
我的ViewModel带有布尔值和字符串:
private bool _isPinVisible;
public bool IsPinVisible
{
get
{
return _isPinVisible;
}
set
{
_isPinVisible = value;
RaisePropertyChanged(nameof(IsPinVisible));
}
}
private string _newaddress;
public string NewAddress
{
get
{
return _newaddress;
}
set
{
_newaddress = value;
RaisePropertyChanged(nameof(NewAddress));
}
}
在我拥有Map.PinClicked事件的Viewmodel中:
Map.PinClicked += (sender, args) =>
{
IsPinVisible = true;
_newaddress = Address;
};
从现在开始单击图钉,将显示一个白色空白区域,但没有文本。当我更新LiveXaml以更改文本颜色时,将显示文本。
答案 0 :(得分:1)
我必须使用NewAddress
Map.PinClicked += (sender, args) =>
{
IsPinVisible = true;
NewAddress = Address;
};