ShowForSelectionAsync() private méthode

private ShowForSelectionAsync ( [ selection ) : IAsyncOperation
selection [
Résultat IAsyncOperation
 async  private void ShowImagePopupMenu(object sender, RightTappedRoutedEventArgs e)
  {
      PopupMenu menu = new PopupMenu();
      menu.Commands.Add(new UICommand("分享到", async (command) =>
      {
          MessageDialog md = new MessageDialog(command.Label);
          await md.ShowAsync();
      }));
      menu.Commands.Add(new UICommand("另存为", async (command) =>
      {
          MessageDialog md = new MessageDialog(command.Label);
          await md.ShowAsync();
      }));
      menu.Commands.Add(new UICommand("编辑", async (command) =>
      {
          MessageDialog md = new MessageDialog(command.Label);
          await md.ShowAsync();
      }));
      menu.Commands.Add(new UICommandSeparator());
      menu.Commands.Add(new UICommand("打印", async (command) =>
      {
          MessageDialog md = new MessageDialog(command.Label);
          await md.ShowAsync();
      }));
      menu.Commands.Add(new UICommand("全屏", async (command) =>
      {
          MessageDialog md = new MessageDialog(command.Label);
          await md.ShowAsync();
      }));
      var chosenCommand = await menu.ShowForSelectionAsync(GetElementRect((FrameworkElement)sender));
  }
        private new async void RightTapped(object sender, RightTappedRoutedEventArgs e)
        {
            Tweet tweet = null;
            var clickBorder = e.OriginalSource as TextBlock;
            if (clickBorder != null)
            {
                tweet = (Tweet)clickBorder.DataContext;
            }
            // Create a menu and add commands specifying a callback delegate for each.
            // Since command delegates are unique, no need to specify command Ids.
            var menu = new PopupMenu();
            menu.Commands.Add(new UICommand("open tweet", (command) =>
            {
                OpenPage(tweet);
            }));
            menu.Commands.Add(new UICommand("copy to clipboard", (command) =>
            {
                CopyText();
            }));


            var chosenCommand = await menu.ShowForSelectionAsync(GetElementRect((FrameworkElement)sender));
            if (chosenCommand == null) // The command is null if no command was invoked.
            {

            }
        }
        private async void MoreButton_Click(object sender, RoutedEventArgs e)
        {
            FrameworkElement element = (FrameworkElement)sender;

            PopupMenu menu = new PopupMenu();
            menu.Commands.Add(new UICommand("姓名", FilterButton_Click, "name"));
            menu.Commands.Add(new UICommand("日期", FilterButton_Click, "date"));

            var clicked = await menu.ShowForSelectionAsync(element.GetElementRect(0, -10), Placement.Above);
        }
 /// <summary>
 /// Displays a PopupMenu for selection of the other Bluetooth device.
 /// Continues by establishing a connection to the selected device.
 /// </summary>
 /// <param name="invokerRect">for example: connectButton.GetElementRect();</param>
 public async Task EnumerateDevicesAsync(Rect invokerRect)
 {
     this.State = BluetoothConnectionState.Enumerating;
     var serviceInfoCollection = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));
     PopupMenu menu = new PopupMenu();
     foreach (var serviceInfo in serviceInfoCollection)
         menu.Commands.Add(new UICommand(serviceInfo.Name, new UICommandInvokedHandler(delegate(IUICommand command) { Task connect = ConnectToServiceAsync(command); }), serviceInfo));
     var result = await menu.ShowForSelectionAsync(invokerRect);
     if (result == null)
         this.State = BluetoothConnectionState.Disconnected;
 }
        private async void ImageOptionsCommand_Click(object sender, RoutedEventArgs e)
        {
            var menu = new PopupMenu();
            menu.Commands.Add(new UICommand("Set Lock Screen", ViewModel.SetLockScreenCommand.Execute));
            menu.Commands.Add(new UICommand("Set Tile", ViewModel.SetTileCommand.Execute));
            if (ApplicationView.Value != ApplicationViewState.Snapped)
            {
                menu.Commands.Add(new UICommand("Save", ViewModel.SaveCommand.Execute));
                menu.Commands.Add(new UICommand("Share", ViewModel.ShareCommand.Execute));
            }

            var chosenCommand = await menu.ShowForSelectionAsync(GetElementRect((FrameworkElement)sender), Placement.Above);
        }
        private async void ReadOnlyTextBox_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            e.Handled = true;
            var textbox = (TextBox)sender;
            if (textbox.SelectionLength > 0)
            {
                // Create a menu and add commands specifying an id value for each instead of a delegate.
                var menu = new PopupMenu();
                menu.Commands.Add(new UICommand("Copy", null, 1));
                menu.Commands.Add(new UICommandSeparator());
                menu.Commands.Add(new UICommand("Highlight", null, 2));
                menu.Commands.Add(new UICommand("Look up", null, 3));

                // We don't want to obscure content, so pass in a rectangle representing the selection area.
                // NOTE: this code only handles textboxes with a single line. If a textbox has multiple lines,
                //       then the context menu should be placed at cursor/pointer location by convention.
                OutputTextBlock.Text = "Context menu shown";
                var rect = GetTextboxSelectionRect(textbox);
                var chosenCommand = await menu.ShowForSelectionAsync(rect);
                if (chosenCommand != null)
                {
                    switch ((int)chosenCommand.Id)
                    {
                        case 1:
                            var selectedText = ((TextBox)sender).SelectedText;
                            var dataPackage = new DataPackage();
                            dataPackage.SetText(selectedText);
                            Clipboard.SetContent(dataPackage);
                            OutputTextBlock.Text = "'" + chosenCommand.Label + "'(" + chosenCommand.Id.ToString() + ") selected; '" + selectedText + "' copied to clipboard";
                            break;

                        case 2:
                            OutputTextBlock.Text = "'" + chosenCommand.Label + "'(" + chosenCommand.Id.ToString() + ") selected";
                            break;

                        case 3:
                            OutputTextBlock.Text = "'" + chosenCommand.Label + "'(" + chosenCommand.Id.ToString() + ") selected";
                            break;
                    }
                }
                else
                {
                    OutputTextBlock.Text = "Context menu dismissed";
                }
            }
            else
            {
                OutputTextBlock.Text = "Context menu not shown because there is no text selected";
            }
        }
        async void Lipsum_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            e.Handled = true;
            TextBox t = (TextBox)sender;

            PopupMenu p = new PopupMenu();
            p.Commands.Add(new UICommand("Cut", null, 0));
            p.Commands.Add(new UICommand("Copy", null, 1));
            p.Commands.Add(new UICommand("Paste", null, 2));
            p.Commands.Add(new UICommand("Select All", null, 3));
            p.Commands.Add(new UICommandSeparator());
            p.Commands.Add(new UICommand("Delete", null, 4));

            var selectedCommand = await p.ShowForSelectionAsync(GetTextBoxRect(t));

            if (selectedCommand != null)
            {
                String text;
                DataPackage d;
                
                switch ((int)selectedCommand.Id)
                {
                    case 0: //CUT
                        text = t.SelectedText;
                        t.SelectedText = "";
                        d = new DataPackage();
                        d.SetText(text);
                        Clipboard.SetContent(d);
                        break;
                    case 1: //COPY
                        text = t.SelectedText;
                        d = new DataPackage();
                        d.SetText(text);
                        Clipboard.SetContent(d);
                        break;
                    case 2: //PASTE
                        text = await Clipboard.GetContent().GetTextAsync();
                        t.SelectedText = text;
                        break;
                    case 3: //SELECT ALL
                        t.SelectAll();
                        break;
                    case 4: //DELETE
                        t.SelectedText = "";
                        break;
                }
            }
        }
 //En esta metodo se muestran los dispositivos que sean del tipo SerialPort en un PopupMenu
 public async Task EnumerateDevicesAsync(Rect invokerRect)
 {
     this.State = BluetoothConnectionState.Enumerating;
     //seleccionamos todos los dispositivos disponibles
     var serviceInfoCollection = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));
     //Creamos el PopupMenu en el que se mostraran los dispositivos
     PopupMenu menu = new PopupMenu();
     //Añadimos los dispositivos encontrados al PopupMenu
     foreach (var serviceInfo in serviceInfoCollection)
         menu.Commands.Add(new UICommand(serviceInfo.Name, new UICommandInvokedHandler(ConnectToServiceAsync), serviceInfo));
    //Seleccionamos el dispositvo con el que nos queremos comunicar
     var result = await menu.ShowForSelectionAsync(invokerRect);
     //Si no se pudo conectar al dispositivo se cambia el estado de la conexion a desconectado
     if (result == null)
         this.State = BluetoothConnectionState.Disconnected;
 }
 private async void OnPhoneModelClicked(object sender, RightTappedRoutedEventArgs e)
 {
     var popup = new PopupMenu();
     popup.Commands.Add(new UICommand("Open", (command) =>
     {
         this.TextBoxResult.Text = "Open...";
     }));
     popup.Commands.Add(new UICommand("Open with", (command) =>
     {
         this.TextBoxResult.Text = "Opened with...";
     }));
     popup.Commands.Add(new UICommand("Save with", (command) =>
     {
         this.TextBoxResult.Text = "Save with...";
     }));
     var chosenCommand = await popup.ShowForSelectionAsync(GetElementRect((FrameworkElement)sender));
     if (chosenCommand == null)
     {
         this.TextBoxResult.Text = "Nothing chosen";
     }
 }
Exemple #10
0
        private async void txtReadOnly_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            // True evita que algunos controladores vuelvan a controlar el evento de nuevo
            e.Handled = true;
            TextBox textBox = (TextBox)sender;

            // Nos aseguramos de haber seleccionado texto
            if (textBox.SelectionLength > 0)
            {
                // Se crea el menu y adicionamos los comandos con sus respectivas id
                var menu = new PopupMenu();
                menu.Commands.Add(new UICommand("Copiar", null, 1));

                // Se crea un rectangulo para el texto seleccionado
                Rect rect = GetTextboxSelectionRect(textBox);

                // Obtenemos de manera asincrona el comando elegido
                var comandoEscogido = await menu.ShowForSelectionAsync(rect);

                if (comandoEscogido != null)
                {
                    // Dependiendo de la cantidad de comandos que tenemos así mismo son los casos
                    switch ((int)comandoEscogido.Id)
                    {
                        case 1:
                            String textoEscogido = txtReadOnly.SelectedText;
                            
                            // Se crea un dataPackege Para poder pasarlo como parametro al ClipBoard
                            var dataPackage = new DataPackage();

                            // Modificamos el texto del dataPackage
                            dataPackage.SetText(textoEscogido);

                            // agregamos finalmente el texto al ClipBoard
                            Clipboard.SetContent(dataPackage);
                            break;
                    }
                }
            }
        }
Exemple #11
0
        private async void AttachmentImage_RightTapped(object sender, RightTappedRoutedEventArgs e)
        {
            // Create a menu and add commands specifying a callback delegate for each.
            // Since command delegates are unique, no need to specify command Ids.
            var menu = new PopupMenu();
            menu.Commands.Add(new UICommand("Open with", (command) =>
            {
                OutputTextBlock.Text = "'" + command.Label + "' selected";
            }));
            menu.Commands.Add(new UICommand("Save attachment", (command) =>
            {
                OutputTextBlock.Text = "'" + command.Label + "' selected";
            }));

            // We don't want to obscure content, so pass in a rectangle representing the sender of the context menu event.
            // We registered command callbacks; no need to handle the menu completion event
            OutputTextBlock.Text = "Context menu shown";
            var chosenCommand = await menu.ShowForSelectionAsync(GetElementRect((FrameworkElement)sender));
            if (chosenCommand == null) // The command is null if no command was invoked.
            {
                OutputTextBlock.Text = "Context menu dismissed";
            }
        }
Exemple #12
0
        /// <summary>
        /// Displays a PopupMenu for selection of the other Bluetooth device.
        /// Continues by establishing a connection to the selected device.
        /// </summary>
        /// <param name="invokerRect">for example: connectButton.GetElementRect();</param>
        public async Task EnumerateDevicesAsync(Rect invokerRect)
        {
            strException = "";

            // The Bluetooth connects intermittently unless the bluetooth settings is launched
            //await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings-bluetooth:"));

            this.State = BluetoothConnectionState.Enumerating;
            var serviceInfoCollection = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));


            PopupMenu menu = new PopupMenu();
            foreach (var serviceInfo in serviceInfoCollection)
                menu.Commands.Add(new UICommand(serviceInfo.Name, new UICommandInvokedHandler(delegate(IUICommand command) { _serviceInfo = (DeviceInformation)command.Id; }), serviceInfo));
            var result = await menu.ShowForSelectionAsync(invokerRect);
            if (result == null)
            {
                // The Bluetooth connects intermittently unless the bluetooth settings is launched
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings-bluetooth:"));

                this.State = BluetoothConnectionState.Disconnected;
            }

            if( _serviceInfo == null)
            {

                strException += "First connection attempt failed\n";

                // The Bluetooth connects intermittently unless the bluetooth settings is launched
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings-bluetooth:"));

                // Update the state
                this.State = BluetoothConnectionState.Disconnected;

            }
        }
        private async void SelectColor(object sender, RoutedEventArgs e)
        {
            var menu = new PopupMenu();
            menu.Commands.Add(new UICommand("Black", null, 1));
            menu.Commands.Add(new UICommand("Red", null, 2));
            menu.Commands.Add(new UICommand("Green", null, 3));
            menu.Commands.Add(new UICommand("Blue", null, 4));
            menu.Commands.Add(new UICommand("Yellow", null, 5));
            menu.Commands.Add(new UICommand("Pink", null, 6));

            IUICommand chosenCommand = await menu.ShowForSelectionAsync(GetElementRect((FrameworkElement)sender));

            if (chosenCommand != null)
            {
                switch ((int)chosenCommand.Id)
                {
                    case 1:
                        _mCurrentDrawingColor = Colors.Black;
                        break;
                    case 2:
                        _mCurrentDrawingColor = Colors.Red;
                        break;
                    case 3:
                        _mCurrentDrawingColor = Colors.Green;
                        break;
                    case 4:
                        _mCurrentDrawingColor = Colors.Blue;
                        break;
                    case 5:
                        _mCurrentDrawingColor = Colors.Yellow;
                        break;
                    case 6:
                        _mCurrentDrawingColor = Colors.Pink;
                        break;
                }

                InkMode();
            }
        }
        // Hierarchy context menu event handlers
        private async void treemapNode_RightTapped(object sender, RightTappedRoutedEventArgs e)
        {
            string menuText = String.Format("Zoom into {0}", (sender as TreemapNode).Hierarchy);
            
            // show a context menu to enable zoom in/out
            var menu = new PopupMenu();

            if (!_zoomedIn)
            {
                menu.Commands.Add(new UICommand(menuText, command =>
                    {
                        ZoomIn(sender);
                    }));
            }
            else
            {
                menu.Commands.Add(new UICommand("Zoom Out", command =>
                    {
                        ZoomOut();
                    }));
            }

            var chosenCommand = await menu.ShowForSelectionAsync(GetElementRect((FrameworkElement)sender));
        }
        private async void UserListSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ListView activeList = (ListView)sender;
            if (activeList.SelectedItem == null)
                return;

            object o = activeList.SelectedItem;
            activeList.SelectedItem = null;
            // Create a menu and add commands specifying a callback delegate for each.
            // Since command delegates are unique, no need to specify command Ids.
            var menu = new PopupMenu();

            string userId = await UserSettings.RetreiveUserId();

            menu.Commands.Add(new UICommand("Go to user", command => HandleGoToUser((User)o)));
            ListViewItem lvi = (ListViewItem)activeList.ItemContainerGenerator.ContainerFromItem(o);

            await menu.ShowForSelectionAsync(GetElementRect(lvi));
        }
        public async void OpenDetailsMenu(object sender)
        {
            var notification = SelectedNotification;
            if (notification != null)
            {
                var menu = new PopupMenu();
                if (!string.IsNullOrEmpty(notification.TargetUrl))
                {
                    menu.Commands.Add(new UICommand("Otwórz link", async (command) =>
                    {
                        if (!string.IsNullOrEmpty(notification.TargetUrl))
                        {
                            await Launcher.LaunchUriAsync(new Uri(notification.TargetUrl));
                        }
                        Notifications = new ObservableCollection<Notification>(await _dataService.SetNotificationAsOld(notification.Id));

                    }));
                }
                if (notification.Status == Core.Enum.NotificationStatus.New)
                {
                    menu.Commands.Add(new UICommand("Ustaw jako przeczytany", async (command) =>
                    {

                        Notifications = new ObservableCollection<Notification>(await _dataService.SetNotificationAsOld(notification.Id));
                    }));
                }

                menu.Commands.Add(new UICommand("Usuń", async (command) =>
                {
                    await _dialogService.ShowMessage("Czy chcesz się usunąc powidomienie?", "Usunięcie", "Tak", "Nie", (confirm) =>
                    {
                        if (confirm)
                        {
                            Notifications.Remove(notification);
                            _dataService.RemoveNotyfication(notification.Id);
                            RefreshView();
                        }
                    });
                }));


                var chosenCommand = await menu.ShowForSelectionAsync(GetElementRect((FrameworkElement)sender));
            }
        }
 private async void showMenu(object sender, RoutedEventArgs e)
 {
     PopupMenu p = new PopupMenu();
     p.Commands.Add(new Windows.UI.Popups.UICommand("Currently", (command) =>
     {
         this.Frame.Navigate(typeof(weatherView));
     }));
     p.Commands.Add(new Windows.UI.Popups.UICommand("12 Hour", (command) =>
     {
         this.Frame.Navigate(typeof(hourlyView));
     }));
     p.Commands.Add(new Windows.UI.Popups.UICommand("7 Day", (command) =>
     {
         this.Frame.Navigate(typeof(threeDayView));
     }));
     p.Commands.Add(new UICommandSeparator());
     p.Commands.Add(new Windows.UI.Popups.UICommand("Cover View", (command) =>
     {
         this.Frame.Navigate(typeof(MainPage));
     }));
     await p.ShowForSelectionAsync(GetRect(sender), Placement.Below);
 }
Exemple #18
0
 private async void AudioTracks_Click(object sender, RoutedEventArgs e)
 {
     PopupMenu popup = new PopupMenu();
     for (int i = 0; i < MathHelper.Clamp(0, 6, Locator.PlayVideoVM.AudioTracksCount); i++)
     {
         popup.Commands.Add(new UICommand()
         {
             Id = Locator.PlayVideoVM.AudioTracks.ElementAt(i).Key,
             Label = Locator.PlayVideoVM.AudioTracks.ElementAt(i).Value,
             Invoked = command => Locator.PlayVideoVM.SetAudioTrackCommand.Execute(command.Id),
         });
     }
     await popup.ShowForSelectionAsync(((Button)sender).GetBoundingRect());
 }
 private async void SelectionButton_Click(object sender, RoutedEventArgs e)
 {
     var selectionButton = (Button)sender;
     var menu = new PopupMenu();
     if (CustomSelectionCommands != null)
     {
         foreach (var command in CustomSelectionCommands)
         {
             menu.Commands.Add(command);
         }
     }
     await menu.ShowForSelectionAsync(selectionButton.GetRect());
 }
 private async void Element_RightTapped(object sender, RightTappedRoutedEventArgs e)
 {
     PopupMenu p = new PopupMenu();
     p.Commands.Add(new UICommand("Blankenburg", (command) => { ((Grid)Logo.Parent).Background = new SolidColorBrush(Colors.Red); }));
     p.Commands.Add(new UICommand("31 Days of Windows 8", (command) => { ((Grid)Logo.Parent).Background = new SolidColorBrush(Colors.Orange); }));
     p.Commands.Add(new UICommandSeparator());
     //p.Commands.Add(new UICommand("Share", (command) => { ((Grid)Logo.Parent).Background = new SolidColorBrush(Colors.Yellow); }));
     p.Commands.Add(new UICommand("Open With...", (command) => { ((Grid)Logo.Parent).Background = new SolidColorBrush(Colors.Green); }));
     p.Commands.Add(new UICommand("Delete", (command) => { ((Grid)Logo.Parent).Background = new SolidColorBrush(Colors.Blue); }));
     p.Commands.Add(new UICommand("Hide With Rectangle", (command) => { HideWithRectangle(sender); }));
     await p.ShowForSelectionAsync(GetRect(sender), Placement.Right);
 }
Exemple #21
0
        private void RenderFaceDetectionResults(Face[] faces)
        {
            ResetFaceDetectionOverlay();
            foreach (var face in faces)
            {
                var heightRatio = SelectedImage.ActualHeight / _currentImage.PixelHeight;
                var widthRatio = SelectedImage.ActualWidth / _currentImage.PixelWidth;
                var localRectHeight = face.FaceRectangle.Height * heightRatio;
                var localRectWidth = face.FaceRectangle.Width * widthRatio;

                Rectangle rect = new Rectangle()
                {
                    Stroke = new SolidColorBrush(Colors.Red),
                    Height = localRectHeight,
                    Width = localRectWidth,
                    IsTapEnabled = true,
                    IsRightTapEnabled = true,
                    IsHitTestVisible = true
                };
                PopupMenu menu = new PopupMenu();


                var horizontalOffset = (PhotoOverlayCanvas.ActualWidth - SelectedImage.ActualWidth) / 2;
                var verticalOffset = (PhotoOverlayCanvas.ActualHeight - SelectedImage.ActualHeight) / 2;

                var localRectLeft = face.FaceRectangle.Left * widthRatio + horizontalOffset;
                var localRectTop = face.FaceRectangle.Top * heightRatio + verticalOffset;

                StackPanel outlinePanel = new StackPanel()
                {
                    IsRightTapEnabled = true,
                    IsHitTestVisible = true,
                    Background = new SolidColorBrush(Colors.Transparent)
                };
                outlinePanel.RightTapped += async (o, e) =>
                {
                    var command = await menu.ShowForSelectionAsync(GetElementRect(o as FrameworkElement));
                };
                outlinePanel.Loaded += (s, e) =>
                {
                    Canvas.SetLeft(outlinePanel, localRectLeft - ((outlinePanel.ActualWidth - localRectWidth) / 2));
                    Canvas.SetTop(outlinePanel, localRectTop - (outlinePanel.ActualHeight - localRectHeight));
                };
                Grid grid = new Grid() { Background = new SolidColorBrush(Colors.White) };
                TextBlock description = new TextBlock()
                {
                    Text = string.Format("{0} year old {1}", face.Attributes.Age, face.Attributes.Gender),
                    Foreground = new SolidColorBrush(Colors.Black),
                    HorizontalAlignment = HorizontalAlignment.Center
                };
                grid.Children.Add(description);
                outlinePanel.Children.Add(grid);
                outlinePanel.Children.Add(rect);
                PhotoOverlayCanvas.Children.Add(outlinePanel);

                menu.Commands.Add(new UICommand("Assign", async (o) =>
                {
                    var selectedFace = o.Id as Face;
                    await AssignFaceToPersonAsync(selectedFace);
                }, face));
                menu.Commands.Add(new UICommand("Identify", async (o) =>
                {
                    var selectedFace = o.Id as Face;
                    var person = await IdentifyPersonAsync(selectedFace);
                    if (person != null)
                    {
                        description.Text = person.Name;
                        Canvas.SetLeft(outlinePanel, localRectLeft - ((outlinePanel.ActualWidth - localRectWidth) / 2));
                    }
                }, face));
            }
        }
        private async void ListViewNotes_RightTapped(object sender, RightTappedRoutedEventArgs e)
        {
            var menu = new PopupMenu();
            menu.Commands.Add(new UICommand("Edit"));

            var chosenCommand = await menu.ShowForSelectionAsync(GetElementRect((FrameworkElement)sender));
            if (chosenCommand.Label == "Edit")
            {
                this.Frame.Navigate(
                typeof(NoteDetailPage),
                sender,
                new Windows.UI.Xaml.Media.Animation.DrillInNavigationTransitionInfo());
            }
        }
Exemple #23
0
        private async void ItemView_ItemRightTapped(object sender, RightTappedRoutedEventArgs e)
        {
            var pos = e.GetPosition(this);

            var elements = VisualTreeHelper.FindElementsInHostCoordinates(pos, ((UIElement)sender));

            FrameworkElement selectedElement = null;
            Station selectedStation = null;

            //I could refactor this
            if (sender is GridView)
            {
                selectedElement = (FrameworkElement)elements.FirstOrDefault(x => x.GetType() == typeof(GridViewItem));
            }
            else if (sender is ListView)
            {
                selectedElement = (FrameworkElement)elements.FirstOrDefault(x => x.GetType() == typeof(ListViewItem));
            }

            if (selectedElement != null)
            {
                e.Handled = true;

                selectedStation = (Station)selectedElement.DataContext;

                PopupMenu menu = new PopupMenu();
                menu.Commands.Add(new UICommand(LocalizationManager.GetLocalizedValue("GotoHomepageMenu"), (command) =>
                {
                    Windows.System.Launcher.LaunchUriAsync(selectedStation.HomepageUrl);
                }));

                this.BottomAppBar.IsSticky = true;
                this.TopAppBar.IsSticky = true;

                var chosenCommand = await menu.ShowForSelectionAsync(new Rect(pos, selectedElement.RenderSize));

                this.BottomAppBar.IsSticky = false;
                this.TopAppBar.IsSticky = false;

            }
        }
        private async void grid_RightTapped(object sender, RightTappedRoutedEventArgs e)
        {
            Position selectedPosition = (sender as Grid).DataContext as Position;
            (DataContext as FriendInfoViewModel).SelectedFriend = SelectedFriend;
            (DataContext as FriendInfoViewModel).SelectedPosition = selectedPosition;
            PopupMenu menu = new PopupMenu();

            menu.Commands.Add(new UICommand(AppResources.General_GetDirections, (command) =>
            {
                staticObjects.GoalLongitude = selectedPosition.Longitude;
                staticObjects.GoalLatitude = selectedPosition.Latitude;
                staticObjects.FriendProfilePicture = new Uri(SelectedFriend.Picture, UriKind.Absolute);
                (DataContext as FriendInfoViewModel).GetDirections.Execute(null);
            }));
            menu.Commands.Add(new UICommand(AppResources.General_ShareFacebook, (command) =>
            {
                Share.ShareToFacebook("http://bing.com/maps/default.aspx" +
                "?cp=" + selectedPosition.Latitude + "~" + selectedPosition.Longitude +
                "&lvl=18" +
                "&style=r",
                String.Format(AppResources.General_LastPositionMessageFriend,
                    SelectedFriend.Name,
                    selectedPosition.Address,
                    selectedPosition.RegisteredAt.ToString() + " GMT",
                    "http://bing.com/maps/default.aspx"), SelectedFriend.Picture);
            }));
            menu.Commands.Add(new UICommand(AppResources.General_ShareEmail, (command) =>
            {
                SetSharingContent(selectedPosition, SelectedFriend.Name);
                Share.ShowShareBar();
            }));

            await menu.ShowForSelectionAsync(Screen.GetElementRect((FrameworkElement)sender));
        }
        async void ellipse_RightTapped(object sender, RightTappedRoutedEventArgs e)
        {
            RedZone zone = (sender as Ellipse).DataContext as RedZone;
            PopupMenu menu = new PopupMenu();

            menu.Commands.Add(new UICommand(AppResources.General_GetDirections, (command) =>
            {
                staticObjects.GoalLongitude = zone.Longitude;
                staticObjects.GoalLatitude = zone.Latitude;
                staticObjects.FriendProfilePicture = new Uri(zone.FbUser.Picture.data.url, UriKind.Absolute);
                (DataContext as RedZonesViewModel).GetDirections.Execute(null);
            }));

            menu.Commands.Add(new UICommand(AppResources.General_ShareFacebook, (command) =>
            {
                Share.ShareToFacebook("http://bing.com/maps/default.aspx" +
                "?cp=" + zone.Latitude + "~" + zone.Longitude +
                "&lvl=18" +
                "&style=r",
                "Sobre la zona " + zone.Address +"."+  
                String.Format(String.Format(
                    AppResources.General_RedZoneWarning_Message,
                    zone.Address,
                    zone.FbUser.Name,
                    zone.Description)),
                zone.FbUser.Picture.data.url);
            }));
            menu.Commands.Add(new UICommand(AppResources.General_ShareEmail, (command) =>
            {
                SetSharingContent(zone, zone.FbUser.Name);
                Share.ShowShareBar();
            }));
            await menu.ShowForSelectionAsync(Screen.GetElementRect((FrameworkElement)sender));
        }
        private async void AppBarUserButton_Click(object sender, RoutedEventArgs e)
        {
            if (Service.Current.IsUsingDefaultCredentials)
            {
                await Service.Current.SignOut();
                return;
            }

            var popupMenu = new PopupMenu();
            popupMenu.Commands.Add(new UICommand(Service.Current.IsUsingDefaultCredentials ? Service.Current.Messages["SignIn"] : Service.Current.Messages["SignOut"], async cmd => await Service.Current.SignOut()));

            var position = this.TransformToVisual(null).TransformPoint(new Point(0, 0));
            await popupMenu.ShowForSelectionAsync(new Rect(position, new Size(ActualWidth, ActualHeight)), Placement.Below);
        }
 async void ShowContextMenuClick(object sender, RoutedEventArgs e)
 {
     var popup = new PopupMenu();
     foreach (var menu in MenuItems)
     {
         var cmd = new UICommand(menu.Text, new UICommandInvokedHandler(_ =>
         {
             menu.OnClick();
         }));
         popup.Commands.Add(cmd);
     }
     var trans = menuButton_.TransformToVisual(Window.Current.Content);
     await popup.ShowForSelectionAsync(
         new Rect(trans.TransformPoint(new Point(0, 0)), 
             trans.TransformPoint(new Point(menuButton_.ActualWidth, menuButton_.ActualHeight))),
         Placement.Above);
 }
        private async void CommentsListSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (CommentsList.SelectedItem == null)
                return;

            object o = CommentsList.SelectedItem;
            CommentsList.SelectedItem = null;
            // Create a menu and add commands specifying a callback delegate for each.
            // Since command delegates are unique, no need to specify command Ids.
            var menu = new PopupMenu();

            string userId = await UserSettings.RetreiveUserId();
            Comment comment = (Comment)o;

            if (userId == _viewModel.CurrentUser.id || userId == comment.from.id)
            {
                menu.Commands.Add(new UICommand("Delete", command => HandleDelete(comment)));
            }
            
            menu.Commands.Add(new UICommand("Go to user", command => HandleGoToUser(comment.from)));

            ListViewItem lvi = (ListViewItem)CommentsList.ItemContainerGenerator.ContainerFromItem(o);

            await menu.ShowForSelectionAsync(GetElementRect(lvi));
        }
        private async void BookmarkItem_RightTapped(object sender, Windows.UI.Xaml.Input.RightTappedRoutedEventArgs e)
        {
            var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
            var hvm = (sender as FrameworkElement).DataContext as HistoryItemViewModel;
            var menu = new PopupMenu();
            var label = resourceLoader.GetString("DeleteBookmarkLabel");

#if WINDOWS_APP
			var newWindowLabel = resourceLoader.GetString("OpenInNewWindowLabel");
			menu.Commands.Add(new UICommand(newWindowLabel, async (command) => {
				await NavigateToReadingPageAsync(hvm.SeriesTitle, hvm.Position, true);
			}));
#endif

            menu.Commands.Add(new UICommand(label, async (command) =>
            {
                await RemoveBookmarkFromFavorite(hvm);
            }));

            try
            {
                var chosenCommand = await menu.ShowForSelectionAsync(GetElementRect((FrameworkElement)sender));
            }
            catch (Exception)
            {
            }
        }
        //void onSettingsCommand(IUICommand command)
        //{
        //    SettingsCommand settingsCommand = (SettingsCommand)command;
        //    this.Frame.Navigate(typeof(PreferencesSettings), prayerViewModel);
        //}

        //void onCommandsRequested(SettingsPane settingsPane, SettingsPaneCommandsRequestedEventArgs eventArgs)
        //{
        //    UICommandInvokedHandler handler = new UICommandInvokedHandler(onSettingsCommand);
        //    var loader = new Windows.ApplicationModel.Resources.ResourceLoader();
        //    SettingsCommand generalCommand = new SettingsCommand("preferencesSettings", loader.GetString("Preferences"), handler);
        //    eventArgs.Request.ApplicationCommands.Add(generalCommand);
        //}

        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            // Create a menu and add commands specifying an id value for each instead of a delegate.
            var menu = new PopupMenu();
            var loader = new Windows.ApplicationModel.Resources.ResourceLoader();
            menu.Commands.Add(new UICommand(loader.GetString("DisplayModesToday"), null, 1));
            menu.Commands.Add(new UICommand(loader.GetString("DisplayModesNextSevenDays"), null, 2));
            menu.Commands.Add(new UICommand(loader.GetString("DisplayModesCurrentMonth"), null, 3));

            // We don't want to obscure content, so pass in a rectangle representing the sender of the context menu event.
            // We registered command callbacks; no need to await and handle context menu completion
            try
            {
                var chosenCommand = await menu.ShowForSelectionAsync(GetElementRect((FrameworkElement)sender));
                if (chosenCommand != null)
                {
                    switch ((int)chosenCommand.Id)
                    {
                        case 1: prayerViewModel.DisplayMode = DisplayModes.Today;
                            break;
                        case 2: prayerViewModel.DisplayMode = DisplayModes.NextSevenDays;
                            break;
                        case 3: prayerViewModel.DisplayMode = DisplayModes.CurrentMonth;
                            break;

                    }
                    await prayerViewModel.LoadPrayers(false);
                }
            }
            catch (Exception)
            {

            }
        }