Click here to Skip to main content
15,301,414 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to set title on title bar at center of microsoft window in wpf>

Please help me!
Posted
Comments
   
By the way, stop re-posting. I won't help you.
--SA

That's not possible without creating Style or use this WPF customizable window[^] I believe it allows you to center the title.

I have to ask, why on earth would you want to do this? Whenever an application does something all other applications does but only in a different way, that is a sign of a bad application. An extreme example would be an application that swaps the OK-Cancel buttons or Yes-No buttons.
   
Comments
Sergey Alexandrovich Kryukov 20-Oct-11 20:26pm
   
Good solution and link, my 5. It all needs some basic explanation which I provided in my solution, please see.
--SA
It is not possible with the standard Window. If you want to do that hen you will have to design a custom window.
   
Comments
Sergey Alexandrovich Kryukov 20-Oct-11 20:27pm
   
Basically, that is correct but does not explain anything and does not provide an idea what to do. I voted 4 and provided some background.
Please see my solution.
--SA
The answer by Wayne and a good solution suggested by Simon require some explanation.

The title bar with window border is called non-client area. If is only accessible by WPF through standard window properties. You cannot render anything in this area. Actually, WPF has very little to do with Windows API; it is based on ActiveX and is not pumping Windows messages, does not use windows handles and other related stuff. It only uses a Windows window as a container. This is explained here: http://msdn.microsoft.com/en-us/library/ms750441.aspx[^].

Now, you can work with non-client area using P/Invoke and raw Window API. This is pretty bad, as the whole idea of WPF is to go away from Windows. Potentially, this foundation is very platform-independent.

I think much better way is to get rid of non-client area at all and simulate missing control elements withing the client area. To do that, you can use the property System.Windows.Window.WindowStyle with the value of System.Windows.WindowStyle.None. See:
http://msdn.microsoft.com/en-us/library/system.windows.window.windowstyle.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.windowstyle.aspx[^].

This way is not so impractical as one could think. This is actually the way to achieve maximum possible window customization and style independence of platform and environment — a blessing for some kinds of application styles.

—SA
   
Comments
Simon Bang Terkildsen 20-Oct-11 22:22pm
   
A good overview
Sergey Alexandrovich Kryukov 20-Oct-11 23:09pm
   
Thank you, Simon.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900