当 运行 提升时,拖放功能工作正常,但当 运行 作为管理员时,拖放功能工作正常

Drag and Drop function works fine when ran unelevated but not when ran as administator

所以我在 wpf 中的 ListView 上设置了拖放功能,就像这样

xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
xmlns:Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras"

<ListView>
   <i:Interaction.Triggers>
       <i:EventTrigger EventName="Drop">
            <Command:EventToCommand Command="{Binding DropFiles}" PassEventArgsToCommand="True"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</ListView>

在我看来我有模型

    private RelayCommand<DragEventArgs> _dropFiles;

    /// <summary>
    /// Gets the DropFiles.
    /// </summary>
    public RelayCommand<DragEventArgs> DropFiles
    {
        get
        {
            return _dropFiles
                ?? (_dropFiles = new RelayCommand<DragEventArgs>(
                args =>
                {
                  //Do Something with args
                }));
        }
    }

这在调试模式下工作正常,但是当我部署这个版本时,当我尝试将我的文件拖放到列表视图中时出现以下图标:

有人知道为什么会这样吗?

更新

如果我 运行 我的项目是管理员,那么拖放功能会如前所述损坏,如果我 运行 我的项目不是管理员,拖放功能可以正常工作。为什么会这样?

所以我不完全理解这一点,但看起来安全是个问题

User Interface Privilege Isolation (UIPI)

Okay, back to our drag and drop issue… A “sister” technology that works in conjunction with MIC is UIPI. UIPI blocks Windows messages being sent from process with a lower MIC level to one running at a higher MIC level. Drag-and-drop is implemented via Windows messages. Therefore, if you try and drag-and-drop a file from Windows Explorer (medium MIC) to Notepad running elevated (high MIC), the Windows messages are blocked and drag-and-drop doesn’t work.

You can use ChangeWindowsMessageFilterEx in your application to allow specified Windows messages to not be blocked. Unfortunately, this isn’t recommended as a safe solution for drag and drop due to the messages that drag and drop uses.

Okay. Now What?

The best solution is to only use drag and drop between the same MIC levels. With UAC enabled, Windows Explorer will run at a medium MIC level. Therefore, your application (Notepad in our example) needs to run at medium (or lower) MIC level. The bottom line is that drag and drop from Windows Explorer will not work if your application is elevated. If you find yourself in this situation, you may need to rethink your application design or not support drag-and-drop with UAC enabled.

取自http://blogs.msdn.com/b/patricka/archive/2010/01/28/q-why-doesn-t-drag-and-drop-work-when-my-application-is-running-elevated-a-mandatory-integrity-control-and-uipi.aspx