简体   繁体   中英

Add button on map when pin/marker is clicked (xamarin forms)

I need to add a button on the map when I've clicked the pin. I use xamarin forms and googlemaps for iOS and Android.

This is my 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>

My ViewModel with the bool and string:

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

My Viewmodel where I have the Map.PinClicked event:

Map.PinClicked += (sender, args) =>
            {
                IsPinVisible = true;
                _newaddress = Address;
            };

Once i click the pin as of right now there is a white blank area that shows but there is no text. When I update LiveXaml to change the textcolor the text is showing.

I had to use NewAddress

 Map.PinClicked += (sender, args) =>
            {
                IsPinVisible = true;
                NewAddress = Address;
            };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM