コンテキスト メニューを定義する DataTemplate があります。
<DataTemplate>
    <TextBlock>
        <TextBlock.ContextMenu>
            <ContextMenu>
                <MenuItem Command="{Binding SendToRecycleBin}" Header="Delete">
            </ContextMenu>
        </TextBlock.ContextMenu>
    </TextBlock>
</DataTemplate>
XAML のみを使用して、ユーザーがコンテキスト メニューを開くときに Shift キーを押した場合にのみ表示される別のメニュー項目をコンテキスト メニューに追加したいと考えています (おそらく、新しい添付プロパティ App.PowerUserOnly を作成しますか?)。
<MenuItem Command="{Binding Delete}" Header="Permanently Delete"
                                     local:App.PowerUserOnly="true">
これは XAML でのみ実行できますか (そうであれば、どのように?)、またはコード ビハインドを使用する必要がありますか?
編集: コンテキスト メニューを開くときに Shift キーを押したままにすると、Windows シェルにも詳細オプションが表示されます。私はその行動をエミュレートしようとしています。たとえば、アプリケーションの高度なオプションの 1 つは、別のユーザーとして実行することです。
人々の提案をテストするのに役立つように、コードを単純化しました。プロジェクトは、ShiftContextMenu という名前のデフォルトの WPF アプリケーションを使用して VS2010 で作成されます。App.xaml および App.xaml.cs ファイルは変更されていません。
MainWindow.xaml:
<Window x:Class="ShiftContextMenu.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <DataTemplate x:Key="DummyItemTemplate">
            <TextBlock Text="{Binding Name}">
                <TextBlock.ContextMenu>
                    <ContextMenu>
                        <MenuItem Command="{Binding SendToRecycleBin}" Header="Delete" />
                        <MenuItem Command="{Binding Delete}" Header="Permanently Delete" />
                    </ContextMenu>
                </TextBlock.ContextMenu>
            </TextBlock>
        </DataTemplate>
    </Window.Resources>
    <TreeView Name="tvMain" ItemTemplate="{StaticResource DummyItemTemplate}" ItemsSource="{Binding DummyItems}" />
</Window>
MainWindow.xaml.cs:
using System.Collections.Generic;
using System.Windows;
using System.Collections.ObjectModel;
namespace ShiftContextMenu
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            DummyItem[] dummyItems = new DummyItem[] {
                new DummyItem("First"),
                new DummyItem("Second"),
                new DummyItem("Third")
            };
            DummyItems = new ReadOnlyCollection<DummyItem>(new List<DummyItem>(dummyItems));
            this.DataContext = this;
            InitializeComponent();
        }
        public ReadOnlyCollection<DummyItem> DummyItems { get; protected set; }
    }
}
ViewModelBase.cs:
using System.ComponentModel;
namespace ShiftContextMenu
{
    public class ViewModelBase : INotifyPropertyChanged
    {
        protected PropertyChangedEventHandler _propertyChangedEvent;
        protected void SendPropertyChanged(string propertyName)
        {
            if (_propertyChangedEvent != null)
            {
                _propertyChangedEvent(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        public event PropertyChangedEventHandler PropertyChanged
        {
            add
            {
                _propertyChangedEvent += value;
            }
            remove
            {
                _propertyChangedEvent -= value;
            }
        }
    }
}
DummyItem.cs:
using System;
using System.Windows.Input;
using System.Windows;
namespace ShiftContextMenu
{
    public class DummyItem : ViewModelBase
    {
        public string Name { get; protected set; }
        public DummyItem(string name)
        {
            Name = name;
            _sendToRecycleBinCommand = new SendToRecycleBinCommand();
            _deleteCommand = new DeleteCommand();
        }
        protected SendToRecycleBinCommand _sendToRecycleBinCommand;
        protected DeleteCommand _deleteCommand;
        public ICommand SendToRecycleBin { get { return _sendToRecycleBinCommand; } }
        public ICommand Delete { get { return _deleteCommand; } }
        protected class SendToRecycleBinCommand : ICommand
        {
            public void Execute(object parameter)
            {
                MessageBox.Show("Send To Recycle Bin");
            }
            public bool CanExecute(object parameter)
            {
                return true;
            }
            public event EventHandler CanExecuteChanged { add { } remove { } }
        }
        protected class DeleteCommand : ICommand
        {
            public void Execute(object parameter)
            {
                MessageBox.Show("Permanently Delete");
            }
            public bool CanExecute(object parameter)
            {
                return true;
            }
            public event EventHandler CanExecuteChanged { add { } remove { } }
        }
    }
}