Set a taskbar text different from the Window title in wpf

后端 未结 3 1978
隐瞒了意图╮
隐瞒了意图╮ 2020-12-11 15:53

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 a

相关标签:
3条回答
  • 2020-12-11 16:12

    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.

    0 讨论(0)
  • 2020-12-11 16:34

    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 讨论(0)
  • 2020-12-11 16:35

    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.

    0 讨论(0)
提交回复
热议问题