Windows 11 - 如何修改 Windows 资源管理器上下文菜单中一组项目的标题?

问题描述 投票:0回答:1

在我的一个应用程序中,我在 Windows 11 的 Windows 资源管理器上下文菜单中添加了一个新项目。这效果很好,但现在我想添加一组项目。我可以通过更新我的应用程序的

AppxManifset.xml
文件来实现这一点,如下所示。

我得到这个结果

但是我希望我的菜单看起来像这样

我知道如何更改我的组中拥有的项目(即“我的第一个命令”和“我的第二个命令”)。为了实现这一点,我可以修改我的项目中从

IExplorerCommand
继承的类。

但我不知道如何修改组项目本身,因为它只存在于我的

appxmanifest.xml
文件中。我想更改标题并显示应用程序图标,如上面的红色箭头所示。

有人可以解释我如何实现这一目标吗?

下面是我的应用程序清单,我从中生成稀疏包:

<?xml version="1.0" encoding="utf-8"?>
<Package
  xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
  xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
  xmlns:uap2="http://schemas.microsoft.com/appx/manifest/uap/windows10/2"
  xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3"
  xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
  xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
  xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4"
  xmlns:desktop5="http://schemas.microsoft.com/appx/manifest/desktop/windows10/5"
  xmlns:uap10="http://schemas.microsoft.com/appx/manifest/uap/windows10/10"
  xmlns:com="http://schemas.microsoft.com/appx/manifest/com/windows10"
  IgnorableNamespaces="uap uap2 uap3 rescap desktop desktop4 desktop5 uap10 com">
    <Identity Name="MyCompany.MyApp" ProcessorArchitecture="x64" Publisher="CN=MyCertificateName, O=MyCertificate, S=MyLocation, C=MU" Version="1.0.2.0" />
    <Properties>
        <DisplayName>My Application</DisplayName>
        <PublisherDisplayName>My Company</PublisherDisplayName>
        <Logo>Assets\storelogo.png</Logo>
        <uap10:AllowExternalContent>true</uap10:AllowExternalContent>
    </Properties>
    <Resources>
        <Resource Language="en-us" />
    </Resources>
    <Dependencies>
        <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.18950.0" MaxVersionTested="10.0.22631.0" />
    </Dependencies>
    <Capabilities>
        <rescap:Capability Name="runFullTrust" />
        <rescap:Capability Name="unvirtualizedResources"/>
    </Capabilities>
    <Applications>
        <Application Id="MyApp" Executable="MyApp.exe" uap10:TrustLevel="mediumIL" uap10:RuntimeBehavior="win32App">
            <uap:VisualElements AppListEntry="none" DisplayName="MyApp" Description="This is my application group." BackgroundColor="transparent" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png">
                <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" Square310x310Logo="Assets\LargeTile.png" Square71x71Logo="Assets\SmallTile.png"></uap:DefaultTile>
                <uap:SplashScreen Image="Assets\SplashScreen.png" />
            </uap:VisualElements>
            <Extensions>
                <desktop4:Extension Category="windows.fileExplorerContextMenus">
                    <desktop4:FileExplorerContextMenus>
                        <desktop5:ItemType Type="Directory">
                            <desktop5:Verb Id="MyFirstCmd" Clsid="11111111-1111-1111-1111-111111111111" />
                            <desktop5:Verb Id="MySecondCmd" Clsid="99999999-9999-9999-9999-999999999999" />
                        </desktop5:ItemType>
                        <desktop5:ItemType Type=".txt">
                            <desktop5:Verb Id="MyFirstCmd" Clsid="11111111-1111-1111-1111-111111111111" />
                            <desktop5:Verb Id="MySecondCmd" Clsid="99999999-9999-9999-9999-999999999999" />
                        </desktop5:ItemType>
                    </desktop4:FileExplorerContextMenus>
                </desktop4:Extension>
                <com:Extension Category="windows.comServer">
                    <com:ComServer>
                        <com:SurrogateServer DisplayName="My application group"> <== !!! THIS HAS NO EFFECT!
                            <com:Class Id="11111111-1111-1111-1111-111111111111" Path="MyAppDll.dll" ThreadingModel="STA"/>
                            <com:Class Id="99999999-9999-9999-9999-999999999999" Path="MyAppDll.dll" ThreadingModel="STA"/>
                        </com:SurrogateServer>
                    </com:ComServer>
                </com:Extension>
            </Extensions>
        </Application>
    </Applications>
</Package>

--------编辑1 --------

我终于找到了如何修改上下文菜单的文本,这是通过更改

DisplayName
文件中下面一行的
AppxManifest.xml
属性的内容:

<uap:VisualElements AppListEntry="none" DisplayName="My application group" Description="This is my application group." BackgroundColor="transparent" Square44x44Logo="Assets\Square44x44Logo.png" Square150x150Logo="Assets\Square150x150Logo.png" />

我还注意到同一行的

Square44x44Logo
属性是项目标题旁边显示的徽标,而我无法显示它的原因是因为文件丢失。

但是,我尝试将缺少的图像文件添加到靠近我的应用程序 exe 文件的资产文件夹中。我使用此演示项目中的图像作为测试:https://github.com/microsoft/AppModelSamples/tree/master/Samples/SparsePackages/PhotoStoreDemoPkg/Assets

我得到这个结果:

所以透明度被打破了。有人可以解释我做错了什么吗?我听说了未电镀的资产问题和一个名为 MakePri.exe 的工具(uap:VisualElements BackgroundColor 无法正常工作),有人有关于此类问题的更多信息吗?

contextmenu menuitem windows-11 group windows-explorer
1个回答
0
投票

经过多方查找,解决方案如下:

  1. 要更改上下文菜单中的组项目名称

名称位于

DisplayName
文件中
<uap:VisualElements>
标签的
AppxManifset.xml
属性中。

<uap:VisualElements AppListEntry="none" DisplayName="My application group" Description="This is my application group." BackgroundColor="transparent" Square44x44Logo="Assets\Square44x44Logo.png" Square150x150Logo="Assets\Square150x150Logo.png" />
  1. 在菜单项标题旁边添加图标

图标在

Square44x44Logo
文件中
<uap:VisualElements>
标签的
AppxManifest.xml
属性中声明。然而,仅仅在 DLL 附近添加一个包含
Asset
文件的
Square44x44Logo.png
文件夹是不够的。在这种情况下,透明度将会丧失。要利用未电镀的资源,您需要编译一个
resources.pri
文件,该文件也应该添加到 DLL 附近。下面的链接解释了如何编译此类文件:

https://learn.microsoft.com/en-us/windows/msix/desktop/desktop-to-uwp-manual-conversion#optional-add-target-based-unlated-assets

通过上述 2 个步骤,组项目将按预期显示在 Windows 11 上下文菜单中。

注意 一旦最终的稀疏包在您的系统中注册并且资源被复制到靠近 DLL 的位置,可能需要重新启动您的 PC 或至少重新启动 Windows 资源管理器任务才能应用更改。

© www.soinside.com 2019 - 2024. All rights reserved.