A Silverlight application does not have a title bar by default. To add a title bar, you modify the window style that App::GetWindowParameters() sets during application initialization.

In the Mastermind code sample, I added a title bar and Minimize button.

Mastermind

I developed the UI for the Mastermind game in Microsoft Expression Blend. When you import the Expression Blend UI project that comes with the Mastermind code sample by using the Windows Embedded Silverlight Tools, the file App.cpp is created. App.cpp contains the code that is run during the initialization of the application.

The function App::GetWindowParameters(XRWindowCreateParams* pWindowParameters) is called during application initialization. The parameter pWindowParameters that is passed to this function is the key to adding the title bar.

Inside App::GetWindowParameters() I set pWindowParameters->Style by using standard Window Styles to add the title bar and Minimize button.

The Mastermind code is: pWindowParameters->Style = WS_VISIBLE | WS_CAPTION | WS_MINIMIZEBOX;

The WS_CAPTION flag makes the title bar visible, and WS_MINIMIZEBOX places a Minimize button on the title bar. That’s all there is to it.

You can also modify the text that appears on the title bar by using the App::GetWindowParameters() function. By default, the generated code loads the application title from the resource file that is also generated when you import your UI project from Expression Blend. You can edit the resource file to change the text for IDS_APP_TITLE if you want different wording to appear in the title bar.

You can use additional window styles if you want to further modify the title bar. For example, if you want a Maximize box, you could add WS_MAXIMIZEBOX to the list of flags in pWindowParameters->Style with a bitwise OR.

Adding a title bar may not be desirable for all Silverlight applications. But if you want to add a title bar to your Silverlight application, the technique described above will do the job.


See Also