Video of the week

This is a must-watch video about one of us trying to reach the stars :-)

Well done #HRejterzy

Windows Phone coding tips

1. How to remove default MessagePrompt button?

Coding4Fun tools are very useful and MessagePrompt control is one used quite often. By default this window has the button at the bottom which seems to be quite unnecessary in some cases. It is possible to remove it or just to change for example for custom Cancel button. How to do it?

MessagePrompt 1

MessagePrompt 2

MessagePrompt 3

  1. MessagePrompt mp = new MessagePrompt();
  3. // Remove default button
  4. mp.ActionPopUpButtons.RemoveAt(0);
  6. // Add new custom button
  7. mp.ActionPopUpButtons.Add(new Button() { Content = "Custom" });
  9. mp.Message = "Hello World!";
  10. mp.Title = "Title";
  12. mp.Show();

2. How to define and use resources using App.xaml resources, ResourceDictionary (MergedDictionaries) in code-behind?

It is not efficient to put all self-defined styles (and other resources) just in one place in App.xaml file. It may happen that half of these definitions which have been load into the memory will not be used at all. It is better to use styles and other resources defined per page and to put only common resources into App.xaml file. Let's define skeleton file for local defined resources:

  1. <ResourceDictionary
  2. xmlns=""
  3. xmlns:x=""
  4. xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
  5. xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">
  7. </ResourceDictionary>

and below we can see properties window and default Build Action:


Copy above code and add to Your project NEW TEXT FILE and change its name (for example CommonStyleDefs) and extension for XAML. To make CommonStyleDefs.xaml file accessible from our common Page use this:


where 'name' equals Your project name.

MergedDictionaries means You can attach more than one ResourceDictionary element. Now we have at least two resource files: App.xaml and CommonStyleDefs.xaml - how to access them in code-behind file:

global App.xaml:

  1. MessagePrompt mp0 = new MessagePrompt();
  2. mp0.Style = App.Current.Resources["commonMessagePromptStyle"] as Style;

local CommonStyleDefs.xaml:

  1. MessagePrompt mp0 = new MessagePrompt();
  2. mp0.Style = this.Resources["localMessagePromptStyle"] as Style;

3. How to use local SQL Server Compact Edition (CE) database file (sdf) as a configuration centre and avoid using XML?

Hope You've got local SQL Server deployment and You will be able to create SDF file using SQL Server Compact Edition and Management Studio:



Local SDF file has been created and now You can connect and manage it using Management Studio to create Tables in the way it is done using typical SQL Server deployment.


Do not forget to set Primary Keys, otherwise You may have some problems trying to insert data into Your new tables. XML file is easy to read using LINQ but it is hard to update and save configuration data. I am not going to rewrite Internet and past here tips that have been described earlier somewhere else. That is why I am going to give another resource to read and get knowledge about what to do next with SQL CE for mobile:

please visit great tutorial page: Visit

4. How to Exit application in Windows Phon 7 to avoid certification issues?

It is not recommended to use throw new Exception("for example Exit"); way to exit application in WP7. Windows Phone 8 API gives new ability to do it in nice and recommended way by using Application.Current.Terminate() method. The nice way we can do it in WP7 is to launch:


  1. // Add Microsoft.Xna.Framework.Game reference before
  2. // Add using Microsoft.Xna.Framework
  4. new Game().Exit();


Proper refernce must be added before:


(Continue soon)