Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Drag and drop functionality in Xamarin

$
0
0

I have searched high and low for something straightforward which explains how to accomplish what I'm trying to do. Well, at least something that starts me down the correct path.

I have an ESRI map control on the page and I generate a group of buttons (or labels, it really doesn't matter). I then want the user to be able to touch the button and drag it onto the map so I can then place them. This seems like it should be fairly simple to do, but I'm not finding anything which explains dragging an object very well. I've looked into LongPress events, GestureRecognizers, etc, and nothing seems to work.

Here is the general layout of the form. I want to drag from the ListView into the Map control. Any suggestions on where I might start?

I cut out some of the namespaces at the top because it won't let me post links yet.

<ContentPage 
             x:Class="AthenaMobile.Views.IncidentCommandView">
    <ContentPage.Resources>
        <ResourceDictionary>
            <local:IncidentCommandViewModel x:Key="IncidentCommandViewModel"/>
        </ResourceDictionary>
    </ContentPage.Resources>
    <ContentPage.Content>
        <Grid >
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid Grid.Row="0" Grid.RowSpan="6" Grid.Column="0" Grid.ColumnSpan="3" BackgroundColor="Gray">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <StackLayout Orientation="Horizontal">
                    <Label TextColor="White" Text="Incident:" VerticalTextAlignment="Center"/>
                    <Picker ItemsSource="{Binding ActiveIncidents}" ItemDisplayBinding="{Binding CfsNumber}" SelectedItem="{Binding SelectedIncident}" VerticalOptions="Center" SelectedIndexChanged="Picker_SelectedIndexChanged"/>
                    <Button Command="{Binding RefreshCallsCommand}" Text="Update Calls" WidthRequest="100" VerticalOptions="Center"/>
                    <Label TextColor="White" FontSize="Large" FontAttributes="Bold" Text="{Binding SelectedIncident.CallTypeId}" VerticalTextAlignment="Center"/>
                </StackLayout>
                <esriUI:MapView Grid.Row="1" Map="{Binding Map, Source={StaticResource IncidentCommandViewModel}}"  x:Name="map" />
            </Grid>
            <Grid Grid.Row="6" Grid.RowSpan="2" Grid.Column="0" Grid.ColumnSpan="3" BackgroundColor="Red">

            </Grid>
            <Grid Grid.Row="0" Grid.RowSpan="6" Grid.Column="3" BackgroundColor="Gray">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Button Grid.Row="0" HorizontalOptions="Center" Text="Units" FontSize="Large" FontAttributes="Bold" TextColor="White" Command="{Binding UnitPressedCommand}" />
                <ListView Grid.Row="1" ItemsSource="{Binding ActiveUnits}">
                    <ListView.ItemTemplate>
                        <DataTemplate>

                            <ViewCell>

                                <StackLayout BackgroundColor="Black" Orientation="Vertical">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="*"/>
                                            <RowDefinition Height="20"/>
                                        </Grid.RowDefinitions>

                                        <Label Grid.Row="0" BackgroundColor="{Binding BackColor}" TextColor="{Binding ForeColor}" Text="{Binding UnitId}" FontSize="Large">
                                            <Label.GestureRecognizers>
                                                <PanGestureRecognizer PanUpdated="Label_PanUpdated"/>
                                            </Label.GestureRecognizers>

                                        </Label>
                                        <Label Grid.Row="1" Text="{Binding UnitStatusIndicator}" FontSize="Medium"/>
                                    </Grid>
                                </StackLayout>
                            </ViewCell>

                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </Grid>
            <Grid Grid.Row="6" Grid.RowSpan="2" Grid.Column="3" BackgroundColor="Yellow">

            </Grid>
        </Grid>

    </ContentPage.Content>
</ContentPage>

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>