문제

In WinRT Applications, when you right click a ListBoxItem the AppBar is shown. But when you right click a GridViewItem the AppBar doesn't appear. Can this be configured?

If not is it beter to work with a ListBox instead of GridView and customize the templates. Or should I implement it With a RightTapped command. (I work with MVVM Light, since Caliburn.Micro is currently not working)

Example of RightTappedCommand:



 public sealed class RightTapped
    {
        #region Properties

        #region Command

        /// 
        /// GetCommand
        /// 
        /// 
        /// 
        public static ICommand GetCommand(DependencyObject obj)
        {
            return (ICommand)obj.GetValue(CommandProperty);
        }

        /// 
        /// SetCommand
        /// 
        /// 
        /// 
        public static void SetCommand(DependencyObject obj, ICommand value)
        {
            obj.SetValue(CommandProperty, value);
        }

        /// 
        /// DependencyProperty CommandProperty
        /// 
        public static readonly DependencyProperty CommandProperty =
            DependencyProperty.RegisterAttached("Command", typeof(ICommand), typeof(RightTapped), new PropertyMetadata(null, OnCommandChanged));

        #endregion Command

        #region CommandParameter

        /// 
        /// GetCommandParameter
        /// 
        /// 
        /// 
        public static object GetCommandParameter(DependencyObject obj)
        {
            return (object)obj.GetValue(CommandParameterProperty);
        }

        /// 
        /// SetCommandParameter
        /// 
        /// 
        /// 
        public static void SetCommandParameter(DependencyObject obj, object value)
        {
            obj.SetValue(CommandParameterProperty, value);
        }

        /// 
        /// DependencyProperty CommandParameterProperty
        /// 
        public static readonly DependencyProperty CommandParameterProperty =
            DependencyProperty.RegisterAttached("CommandParameter", typeof(object), typeof(RightTapped), new PropertyMetadata(null, OnCommandParameterChanged));

        #endregion CommandParameter

        #region HasCommandParameter

        private static bool GetHasCommandParameter(DependencyObject obj)
        {
            return (bool)obj.GetValue(HasCommandParameterProperty);
        }

        private static void SetHasCommandParameter(DependencyObject obj, bool value)
        {
            obj.SetValue(HasCommandParameterProperty, value);
        }

        private static readonly DependencyProperty HasCommandParameterProperty =
            DependencyProperty.RegisterAttached("HasCommandParameter", typeof(bool), typeof(RightTapped), new PropertyMetadata(false));

        #endregion HasCommandParameter

        #endregion Propreties

        #region Event Handling

        private static void OnCommandParameterChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            SetHasCommandParameter(o, true);
        }

        private static void OnCommandChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            var element = o as FrameworkElement;
            if (element != null)
            {
                if (e.NewValue == null)
                {
                    element.RightTapped -= FrameworkElementKeyUp;
                }
                else if (e.OldValue == null)
                {
                    element.RightTapped += FrameworkElementKeyUp;
                }
            }
        }

        private static void FrameworkElementKeyUp(object sender, RightTappedRoutedEventArgs e)
        {
            var o = sender as DependencyObject;
            var command = GetCommand(sender as DependencyObject);

            var element = e.OriginalSource as FrameworkElement;
            if (element != null)
            {
                // If the command argument has been explicitly set (even to NULL) 
                if (GetHasCommandParameter(o))
                {
                    var commandParameter = GetCommandParameter(o);

                    // Execute the command 
                    if (command.CanExecute(commandParameter))
                    {
                        command.Execute(commandParameter);
                    }
                }
                else if (command.CanExecute(element.DataContext))
                {
                    command.Execute(element.DataContext);
                }
            }
        }

        #endregion
    }

In Xaml, something like this:

common:Tapped.Command="{Binding ShowAppBar}"
도움이 되었습니까?

해결책

You can just do myAppBar.IsOpen = true.

다른 팁

It depends on the gridview selection mode, the right-click is used for selecting items. If you set the selectionmode property to None the appbar will open on right-click.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top