开发者

Set a taskbar text different from the Window title in wpf

开发者 https://www.devze.com 2023-02-02 20:48 出处:网络
I develop with VS2010 in C# and I would like to create a WPF Window which have a taskbar text different from the Window title.

I develop with VS2010 in C# and I would like to create a WPF Window which have a taskbar text different from the Window title. The property Title set both the window title and the taskbar text. Is ther开发者_JAVA百科e a way to set them separatly?


First, let me reinforce what Cody Gray said in both his answer and comment - this is non-standard behavior, and you should have a darn good reason for doing this.

That being said, I would take a nearly opposite approach to Cody's point #1. I would create a window WindowStyle set to None, and recreate the title bar (which could include the icon, your "pseudo-title," minimize, maximize, and close buttons, and perhaps even the standard Windows menu. You will also need to handle resizing (which can be done by setting ResizeMode to CanResizeWithGrip, but it adds a Grip control to the bottom of your window, which makes it look slightly different than a "normal" window).

The Title property of this window would then be the Title you want to show in the Taskbar, and the "pseudo-title" in the title bar you create would just be a Label or TextBlock bound to whatever you want your window to show.

It is a little complex, but really not too difficult to do. You will probably run into some Gotchas along the way (for instance, how the Window looks on different OS's or with different Windows themes applied). The nice thing is that it requires no Interop, and a majority of it can be attained using XAML only.

There are lots of examples online (here is one I picked at random).

Again, you'll have to decide if it is worth the effort to create a non-standard behavior. YMMV.


Basically, you have two options:

  1. Draw the taskbar button yourself, rather than letting Windows handle it. This is actually reasonably simple, as far as owner drawing things goes.

  2. Manage two different forms/windows simultaneously. You'll need to create a hidden main window that will appear on the taskbar and own your second window. Your second window will be visible, display its own caption on its title bar, and contain your actual user interface, but won't show up on the taskbar (set its ShowInTaskbar property to "False"). You'll have to write code to show the second window whenever the first one is activated using the taskbar.

I recommend that before starting down either one of these paths, you carefully consider whether you really need this "functionality". It's difficult to tell what goes with what if you have what is effectively one window with different names in different places.


try to use this: http://www.codeguru.com/forum/showthread.php?t=3833 in conjunction with http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6b97a6de-0480-4339-8ed0-cb7cdb27bd83

The first one works fine for me in classical .NET form application when I have made window without title bar and want some text in task bar icon. The second one you need to handle low level WIN32 messages in WPF window (but this works only for top level one).

0

精彩评论

暂无评论...
验证码 换一张
取 消