Inheritance: IPopupMenu
Esempio n. 1
0
        private async void OnTapped(object sender, TappedRoutedEventArgs e)
        {
            TextBlock tb = sender as TextBlock;
            PopupMenu menu = new PopupMenu();
            UICommandInvokedHandler invokedHandler = (cmd) =>
            {
                SolidColorBrush brush = cmd.Id as SolidColorBrush;
                tb.Foreground = brush;
            };

            UICommand cmdRed = new UICommand("红", invokedHandler, new SolidColorBrush(Colors.Red));
            UICommand cmdOrange = new UICommand("橙", invokedHandler, new SolidColorBrush(Colors.Orange));
            UICommand cmdPurple = new UICommand("紫", invokedHandler, new SolidColorBrush(Colors.Purple));

            menu.Commands.Add(cmdRed);
            menu.Commands.Add(cmdOrange);
            menu.Commands.Add(cmdPurple);

            GeneralTransform gt = tb.TransformToVisual(null);

            Point popupPoint = gt.TransformPoint(new Point(0d, tb.ActualHeight));

            await menu.ShowAsync(popupPoint);


        }
        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.
            {

            }
        }
        public ResetPopup(Player[] player, Frame Mainpage, UICommandInvokedHandler resetMenu)
        {
            this._mainPage = Mainpage;
            this._player = player;
            string[] list = new string[_player.Length + 2];
      


            for (int i = 0; i < _player.Length; i++)
            {
                
                list[i] = _player[i].Name + " Wins";
                
            }

            list[_player.Length] = "Draw";
            list[_player.Length + 1] = "Reset Score";


            _pM = Class.CreateXAMLObj.CreatePopup(list);
            

            for (int i = 0; i < _player.Length+2; i++)
            {
                _pM.Commands[i].Invoked = resetMenu;
                
            }
            
            
            
             
        }
Esempio n. 4
0
 public Windows.UI.Popups.PopupMenu get()
 {
     var menu = new Windows.UI.Popups.PopupMenu();
     foreach (var cmd in Commands)
     {
         if (cmd is Separator)
         {
             menu.Commands.Add(new UICommandSeparator());
         }
         else
         {
             var item = cmd as MenuItem;
             menu.Commands.Add(new UICommand(item.Header, param =>
             {
                 if (item.Command != null)
                 {
                     item.Command.Execute(param);
                 }
                 else
                 {
                     item.OnClick();
                 }
             }, item.CommandParameter));
         }
     }
     return menu;
 }
 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 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);
        }
Esempio n. 7
0
        public async Task showPopupMenu(string msg)
        {

            PopupMenu dialog = new PopupMenu();
            dialog.Commands.Add(new UICommand(msg, OnCommand, 0));
            dialog.Commands.Add(new UICommand("No", OnCommand, 1));
            dialog.Commands.Add(new UICommandSeparator());
            dialog.Commands.Add(new UICommand("Close", OnCommand, 2));
            await dialog.ShowAsync(new Point(10, 10));
        }
 /// <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;
 }
        async void OnTextBlockRightTapped(object sender, RightTappedRoutedEventArgs e) {
            PopupMenu popupMenu = new PopupMenu();
            popupMenu.Commands.Add(new UICommand("Larger Font", OnFontSizeChanged, 1.2));
            popupMenu.Commands.Add(new UICommand("Smaller Font", OnFontSizeChanged, 1 / 1.2));
            popupMenu.Commands.Add(new UICommandSeparator());
            popupMenu.Commands.Add(new UICommand("Red", OnColorChanged, Colors.Red));
            popupMenu.Commands.Add(new UICommand("Green", OnColorChanged, Colors.Green));
            popupMenu.Commands.Add(new UICommand("Blue", OnColorChanged, Colors.Blue));

            await popupMenu.ShowAsync(e.GetPosition(this));
        }
        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);
        }
        public static PopupMenu CreatePopup(String[] list)
        {
            PopupMenu p = new PopupMenu();

            for (int i = 0; i < list.Length; i++)
            {
                p.Commands.Add(new UICommand(list[i]));

                p.Commands[i].Id = list.Length - i - 1;
            }

            return p;
        }
        private async void BtnAvatar_OnClick(object sender, RoutedEventArgs e)
        {
            var popupMenu = new PopupMenu();

            popupMenu.Commands.Add(new UICommand("From File", AvatarFromFile));
            popupMenu.Commands.Add(new UICommand("From Camera", AvatarFromCamera));

            var button = (Button)sender;
            var transform = button.TransformToVisual(this);
            var point = transform.TransformPoint(new Point(45, -10));
            
            await popupMenu.ShowAsync(point);
        }
Esempio n. 13
0
        public override void ActionSheet(ActionSheetConfig config)
        {
            var sheet = new PopupMenu();
            foreach (var opt in config.Options)
                sheet.Commands.Add(new UICommand(opt.Text, x => opt.TryExecute()));

            if (config.Cancel != null)
                sheet.Commands.Add(new UICommand(config.Cancel.Text, x => config.Cancel.TryExecute()));

            if (config.Destructive != null)
                sheet.Commands.Add(new UICommand(config.Destructive.Text, x => config.Destructive.TryExecute()));

            sheet.ShowAsync(new Point(0, 0));
        }
Esempio n. 14
0
        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";
            }
        }
        private async void HandleMoreButton(object sender, RoutedEventArgs e)
        {
            var popup = new PopupMenu();
            popup.Commands.Add(new UICommand("Take Picture", (args) => {

                // try and unsnap, then show...
                if(ApplicationView.TryUnsnap())
                    this.ViewModel.TakePhotoCommand.Execute(null);

            }));
            popup.Commands.Add(new UICommand("Capture Location", (args) =>  this.ViewModel.CaptureLocationCommand.Execute(null)));

            // show...
            await popup.ShowAsync(((FrameworkElement)sender).GetPointForContextMenu());
        }
Esempio n. 16
0
        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";
     }
 }
Esempio n. 19
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;
                    }
                }
            }
        }
        private async void HandleMoreButton(object sender, RoutedEventArgs e)
        {
            var popup = new PopupMenu();
            popup.Commands.Add(new UICommand("Take Picture", async (args) =>
            {

                //// try and unsnap, then show...
                //if (ApplicationView.TryUnsnap())
                //    this.ViewModel.TakePhotoCommand.Execute(null);

                await this.ShowAlertAsync("Make the app full screen to use the camera.");

            }));
            popup.Commands.Add(new UICommand("Capture Location", (args) => 
            {
                var viewModel = (IEditReportPageViewModel)this.GetViewModel();
                viewModel.CaptureLocationCommand.Execute(null);
            }));

            // show...
            await popup.ShowAsync(((FrameworkElement)sender).GetPointForContextMenu());
        }
Esempio n. 21
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";
            }
        }
Esempio n. 22
0
        private async void ellipse_RightTapped(object sender, RightTappedRoutedEventArgs e)
        {
            Friend selectedFriend = (sender as Ellipse).DataContext as Friend;
            (DataContext as FriendsViewModel).SelectedFriend = selectedFriend;
            PopupMenu menu = new PopupMenu();

            menu.Commands.Add(new UICommand(AppResources.General_SeeMore, (command) =>
            {
                (DataContext as FriendsViewModel).TapOnFriend.Execute(null);
            }));
            menu.Commands.Add(new UICommand(AppResources.General_GetDirections, (command) =>
            {
                staticObjects.GoalLongitude = selectedFriend.LastPosition.Longitude;
                staticObjects.GoalLatitude = selectedFriend.LastPosition.Latitude;
                staticObjects.FriendProfilePicture = new Uri(selectedFriend.Picture, UriKind.Absolute);
                (DataContext as FriendsViewModel).GetDirections.Execute(null);
            }));

            menu.Commands.Add(new UICommand(AppResources.General_ShareFacebook, (command) =>
            {
                Share.ShareToFacebook("http://bing.com/maps/default.aspx" +
                "?cp=" + selectedFriend.LastPosition.Latitude + "~" + selectedFriend.LastPosition.Longitude +
                "&lvl=18" +
                "&style=r",
                String.Format(AppResources.General_LastPositionMessageFriend, 
                    selectedFriend.Name, 
                    selectedFriend.LastPosition.Address, 
                    selectedFriend.LastPosition.RegisteredAt.ToString()+ " GMT", 
                    "http://bing.com/maps/default.aspx"),selectedFriend.Picture);
            }));
            menu.Commands.Add(new UICommand(AppResources.General_ShareEmail, (command) =>
            {
                SetSharingContent(selectedFriend);
                Share.ShowShareBar();
            }));
            await menu.ShowForSelectionAsync(Screen.GetElementRect((FrameworkElement)sender));
        }
Esempio n. 23
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 void speedButton_Click(object sender, RoutedEventArgs e)
        {
            // Create menu and add commands
            var popupMenu = new PopupMenu();

            popupMenu.Commands.Add(new UICommand("4.0x", command => CurrentPlayer.PlaybackRate = 4.0));
            popupMenu.Commands.Add(new UICommand("2.0x", command => CurrentPlayer.PlaybackRate = 2.0));
            popupMenu.Commands.Add(new UICommand("1.5x", command => CurrentPlayer.PlaybackRate = 1.5));
            popupMenu.Commands.Add(new UICommand("1.0x", command => CurrentPlayer.PlaybackRate = 1.0));
            popupMenu.Commands.Add(new UICommand("0.5x", command => CurrentPlayer.PlaybackRate = 0.5));

            // Get button transform and then offset it by half the button
            // width to center. This will show the popup just above the button.
            var button = (Button)sender;
            var transform = button.TransformToVisual(null);
            var point = transform.TransformPoint(new Point(button.Width / 2, 0));
            
            // Show popup
            var ignoreAsyncResult = popupMenu.ShowAsync(point);

        }
Esempio n. 25
0
 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);
 }
        protected override async void OnTapped(TappedRoutedEventArgs e)
        {
            if (!e.Handled)
            {
                var source = e.OriginalSource as FrameworkElement;
                if (source != null)
                {
                    var attr = DataContext as PersistentObjectAttribute;
                    if (attr != null)
                    {
                        var args = new AttributeContextMenuArgs(attr);
                        ((StoreHooks)Service.Current.Hooks).AttributeContextMenu(args);
                        if (args.Commands.Count > 0)
                        {
                            if (args.AutoExecuteFirst && args.Commands.Count == 1)
                                args.Commands[0].Invoked(args.Commands[0]);
                            else
                            {
                                var popupMenu = new PopupMenu();
                                args.Commands.Run(popupMenu.Commands.Add);

                                var point = source.TransformToVisual(null).TransformPoint(e.GetPosition(this));
                                await popupMenu.ShowAsync(point);
                            }

                            e.Handled = true;
                        }
                    }
                }
            }

            base.OnTapped(e);
        }
Esempio n. 27
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());
 }
        /// <summary>
        /// Shows a <see cref="PopupMenu"/>.
        /// </summary>
        /// <param name="tag">
        /// The tag of the anchor view (the <see cref="PopupMenu"/> is
        /// displayed next to this view); this needs to be the tag of a native
        /// view (shadow views cannot be anchors).
        /// </param>
        /// <param name="items">The menu items as an array of strings.</param>
        /// <param name="success">
        /// A callback used with the position of the selected item as the first
        /// argument, or no arguments if the menu is dismissed.
        /// </param>
        public void ShowPopupMenu(int tag, string[] items, ICallback success)
        {
            DispatcherHelpers.AssertOnDispatcher();
            var view = ResolveView(tag);

            var menu = new PopupMenu();
            for (var i = 0; i < items.Length; ++i)
            {
                menu.Commands.Add(new UICommand(
                    items[i],
                    cmd =>
                    {
                        success.Invoke(cmd.Id);
                    },
                    i));
            }

            // TODO: figure out where to popup the menu
            // TODO: add continuation that calls the callback with empty args
            throw new NotImplementedException();
        }
Esempio n. 29
0
        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));
        }
Esempio n. 30
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;

            }
        }