EventArgs in commands

Hi,

I'm working with a component called TK.CustomMaps which is a extended version of the Xamarin.Forms.Maps element. There are few examples but I'm pretty sure this will let me accomplish what I want. Now, what I'm trying to do is to set a pin on a a TKCustomMap element when the user clicks on a position in the map. Using intellisense I can see that the control has the following options "MapClicked (Event)" and MapClickedCommand. I'm using MVVMLight so basically what I'm trying to do is bind the MapClickedCommand to a relaycommand and add the code to add the pins on that method. The thing is that I'm not sure how to pass the event args to the command, basically the position or the dynamic information I will use to create my pins.

Here is what I have so far:

XAML
<tkmap:TKCustomMap MapClickedCommand="{Binding MapClickCommand}" VerticalOptions="FillAndExpand" />

ViewModel
MapClickCommand = new RelayCommand (() => Test ());
private void Test ()
{
//I want to create the dynamic pins here.
}

@TorbenKruse
-Hi Torben, I believe you are the author of this component. Would you give me some advice in how to accomplish what I want? I want users to be able to set the pins, remove them as well as circle radius dynamically.

Thanks in advance

Answers

  • TorbenKruseTorbenKruse DEMember ✭✭✭

    In the current version on NuGet you have to use Command<Position>

  • JuanPabloSillerJuanPabloSiller USMember ✭✭

    I changed the code to look like this but whenever I click the map nothing happens:

    View
    <tkmap:TKCustomMap VerticalOptions="FillAndExpand" MapClickedCommand="{Binding TestCommand}" />

    ViewModel
    public RelayCommand<Position> TestCommand { get; private set; }

    Constructor
    TestCommand = new RelayCommand<Position> ((s) => Test (s));

    private void Test (Position s)
            {
                object t = s;
                //I want to create the dynamic pins here.
            }
    

    If I set a breakpoint in line "object t = s;" just to test the method is being triggered nothing happens whenever I click the map, am I using the MapClickedCommand property incorrectly?

    Thanks
    Regards

Sign In or Register to comment.