c# - 如何防止 WPF 应用程序中的开始菜单固定
问题描述
使用WindowsAPICodePack.Shell
我试图阻止用户将 WPF 应用程序固定到开始菜单和任务栏。我在 Windows 10 机器上执行此操作。
我尝试了两种方法,都阻止固定到任务栏,但仍然可以固定到开始菜单。
选项1
public void PreventPin()
{
Window parentWindow = Window.GetWindow(ShellWindow);
string appID = "UI";
Guid propGuid = new Guid("{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}");
PropertyKey idProperty = new PropertyKey(propGuid, 5); // System.AppUserModel.ID
PropertyKey preventTaskbarPinning = new PropertyKey(propGuid, 9); // System.AppUserModel.PreventPinning
PropertyKey preventStartPinning = new PropertyKey(propGuid, 12); // System.AppUserModel.PreventPinning
//Important: Set PreventPinning before ID
WindowProperties.SetWindowProperty(parentWindow, preventTaskbarPinning, "True");
WindowProperties.SetWindowProperty(parentWindow, preventStartPinning, "2");
WindowProperties.SetWindowProperty(parentWindow, idProperty, appID);
}
选项 2 - 在 HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileAssociation\NoStartPageAppUserModelIDs\ 的注册表中也存在 UI,并带有“UI”条目
public void PreventPin()
{
Window parentWindow = Window.GetWindow(ShellWindow);
string appID = "UI";
Guid propGuid = new Guid("{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}");
PropertyKey idProperty = new PropertyKey(propGuid, 5); // System.AppUserModel.ID
WindowProperties.SetWindowProperty(parentWindow, idProperty, appID);
}
任何想法我做错了什么?
一些参考资料:
https://docs.microsoft.com/en-us/previous-versions//jj553605(v=vs.85)?redirectedfrom=MSDN
解决方案
我有个提议,设置你的主窗口,防止用户在windows上使用其他资源:
WindowStyle="None" WindowState="Maximized"
这不是最好的解决方案,它只会显示您的应用程序。
推荐阅读
- excel - 如果缺少,请按特定顺序添加工作表
- java - 在没有`while`循环的情况下编写Java Kafka消费者应用程序
- excel - 关闭前的工作簿 不为某些人工作,但为其他人工作
- c# - 执行参数工作不正确的查询
- angularjs - 范围数组在模糊时不受影响
- ios - Definitive -- 获取 TableViewCell 图像以停止闪烁
- r - 如何在通过对象 B 分组时连接新对象中的所有值
- ios - 如何为 Project Catalyst 构建 OpenSSL 库?
- java - C#.Net 中的 RSA SHA256 文件签名和 Java 验证
- c# - 如何从 WCF 数据服务中获取已排序的实体列表?