예제 #1
0
 private void FireViewmodelCommand(object viewModel, string commandName, MapSelectionParameters selParams)
 {
     if (viewModel != null && !string.IsNullOrWhiteSpace(commandName))
     {
         var dcType        = viewModel.GetType();
         var commandGetter = dcType.GetRuntimeMethod("get_" + commandName, new Type[0]);
         if (commandGetter != null)
         {
             var command = commandGetter.Invoke(viewModel, null) as ICommand;
             if (command != null)
             {
                 command.Execute(selParams);
             }
         }
     }
 }
예제 #2
0
        private void AddEventMapping(EventToCommandMapper mapper)
        {
            Observable.FromEventPattern <object>(AssociatedObject, mapper.EventName)
            .Subscribe(se =>
            {
                Point?tapPoint        = null;
                var mapInputEventArgs = se.EventArgs as MapInputEventArgs;
                if (mapInputEventArgs != null)
                {
                    tapPoint = mapInputEventArgs.Position;
                }
                if (tapPoint == null)
                {
                    var tappedRoutedEventArgs = se.EventArgs as TappedRoutedEventArgs;
                    if (tappedRoutedEventArgs != null)
                    {
                        tapPoint = tappedRoutedEventArgs.GetPosition(this.AssociatedObject);
                    }
                }

                if (tapPoint != null)
                {
                    Debug.WriteLine("Tapped on {0},{1} on LayerName {2}", tapPoint.Value.X, tapPoint.Value.Y, LayerName);

                    var shapes    = AssociatedObject.FindMapElementsAtOffset(tapPoint.Value);
                    var selParams = new MapSelectionParameters
                    {
                        LayerName  = LayerName,
                        SelectTime = DateTimeOffset.Now
                    };
                    var t = shapes.Count(p => p.GetLayerName() == LayerName);
                    if (t != 0)
                    {
                        Debug.WriteLine("Found {0} shapes on layer {1}", t, LayerName);
                    }

                    foreach (var shape in shapes.Where(p => p.GetLayerName() == LayerName))
                    {
                        FireViewmodelCommand(shape.ReadData <ViewModelBase>(), mapper.CommandName, selParams);
                    }
                }
            });
        }