如何在 WPF 中进行 AppBar 对接(到屏幕边缘,如 WinAmp)?
是否有关于在 WPF 中进行 AppBar 对接(例如锁定到屏幕边缘)的完整指南? 我知道需要进行 InterOp 调用,但我正在寻找基于简单 WPF 表单的概念证明,或者可以使用的组件化版本。
相关资源:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我花了几周时间探索这一挑战,并最终创建了一个非常可靠的 NuGet 包,以非常友好的方式提供了此功能。 只需创建一个新的 WPF 应用程序,然后将主窗口的类从 Window 更改为 DockWindow(在 XAML 中)即可!
在此处获取包并查看演示应用程序的 Git 存储库。
I've spent some weeks exploring this challenge and finally created a very solid NuGet package delivering this functionality in very friendly way. Simply create a new WPF app then change the main window's class from Window to DockWindow (in the XAML) and that's it!
Get the package here and see the Git repo for a demonstration app.
作为商业替代方案,请参阅 WPF 的即用型 ShellAppBar 组件,该组件支持所有情况和场景,例如任务栏停靠到左、右、上、下边缘,支持多个显示器,拖动停靠,自动隐藏等。与尝试自己处理所有这些情况相比,它可能会节省您的时间和金钱。
免责声明:我在 LogicNP Software 工作,该公司是 ShellAppBar 的开发者。
As a commercial alternative, see the ready-to-use ShellAppBar component for WPF which supports all cases and secnarios such as taskbar docked to left,right,top,bottom edge, support for multiple monitors, drag-docking, autohide , etc etc. It may save you time and money over trying to handle all these cases yourself.
DISCLAIMER: I work for LogicNP Software, the developer of ShellAppBar.
抱歉,调整任务栏大小时,我发布的最后一个代码不起作用。 以下代码更改似乎效果更好:
Sorry, the last code I posted didn't work when the Taskbar is resized. The following code change seems to work better:
我修改了 Philip Rieck 的代码(顺便说一句,非常感谢)以在多个显示设置中工作。 这是我的解决方案。
I modified code from Philip Rieck (btw. Thanks a lot) to work in multiple display settings. Here's my solution.
请注意:这个问题收集了大量反馈,下面的一些人提出了很好的观点或修复。 因此,虽然我将代码保留在这里(并可能更新它),但我还创建了一个 WpfAppBar github上的项目。 请随意发送拉取请求。
同一个项目还构建为 WpfAppBar nuget 包
我从中提供的第一个链接中获取了代码问题( http://www.codeproject.com/KB/dotnet/AppBar.aspx< /a> )并对其进行修改以执行两件事:
此方法不会创建基类。
要使用,只需从普通 wpf 窗口中的任何位置调用此代码(例如单击按钮或初始化)。 请注意,在窗口初始化之后才能调用此函数,如果尚未创建 HWND(如在构造函数中),则会发生错误。
使窗口成为应用程序栏:
将窗口恢复为普通窗口:
这是该文件的完整代码 - 注意您需要将第 7 行的命名空间更改为适当的内容。
Please Note: This question gathered a good amount of feedback, and some people below have made great points or fixes. Therefore, while I'll keep the code here (and possibly update it), I've also created a WpfAppBar project on github. Feel free to send pull requests.
That same project also builds to a WpfAppBar nuget package
I took the code from the first link provided in the question ( http://www.codeproject.com/KB/dotnet/AppBar.aspx ) and modified it to do two things:
This approach doesn't create a base class.
To use, just call this code from anywhere within a normal wpf window (say a button click or the initialize). Note that you can not call this until AFTER the window is initialized, if the HWND hasn't been created yet (like in the constructor), an error will occur.
Make the window an appbar:
Restore the window to a normal window:
Here's the full code to the file - note you'll want to change the namespace on line 7 to something apropriate.
抱歉我的英语...这是 Philip Rieck 的解决方案,其中包含一些更正。 它可以正确处理任务栏位置和大小的变化。
您可以为左边缘和右边缘编写相同的代码。
干得好,菲利普·里克,谢谢你!
Sorry for my English... Here is the Philip Rieck's solution with some corrects. It correctly works with Taskbar position and size changes.
The same code you can write for the Left and Right edges.
Good job, Philip Rieck, thank you!
1996 年有一篇精彩的 MSDN 文章,更新得很有趣:使用应用程序桌面工具栏扩展 Windows 95 Shell。 遵循其指导会生成一个基于 WPF 的应用程序栏,该应用程序栏可处理本页上其他答案所无法处理的多种情况:
我有一个 演示应用程序和
AppBarWindow
的实现在 GitHub 上 并作为 Nuget 模块。使用示例:
代码隐藏:
更改停靠位置:
用拇指调整大小:
与其他应用栏的合作:
如果您想使用它,请从 GitHub 克隆。 该库本身只有三个文件,可以轻松地放入项目中。
There is an excellent MSDN article from 1996 which is entertainingly up to date: Extend the Windows 95 Shell with Application Desktop Toolbars. Following its guidance produces an WPF based appbar which handles a number of scenarios that the other answers on this page do not:
I have both a demo app and the implementation of
AppBarWindow
on GitHub and as a Nuget module.Example use:
Codebehind:
Changing docked position:
Resizing with thumb:
Cooperation with other appbars:
Clone from GitHub if you want to use it. The library itself is only three files, and can easily be dropped in a project.
很高兴发现这个问题。 上面的类确实很有用,但并没有完全涵盖 AppBar 实现的所有基础。
要完全实现 AppBar 的所有行为(处理全屏应用程序等),您还需要阅读这篇 MSDN 文章。
http://msdn.microsoft.com/en-us/library/bb776821。 ASPX
Very happy to have found this question. Above class is really useful, but doesnt quite cover all the bases of AppBar implementation.
To fully implement all the behaviour of an AppBar (cope with fullscreen apps etc) you're going to want to read this MSDN article too.
http://msdn.microsoft.com/en-us/library/bb776821.aspx