I have a problem calling Guide.BeginShowMessageBox
Here is my code:
public object FuelTypeIndex { get; private set; }
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
var messageCommands = new Dictionary<string, Action>()
{
{ "Diesel", () => {FuelTypeIndex = 0;}},
{ "Petrol", () => {FuelTypeIndex = 1;}},
{ "Other", () => {FuelTypeIndex = 2;}},
};
var result = Guide.BeginShowMessageBox("Title", "Message", messageCommands.Keys, 0, MessageBoxIcon.Warning, null, null);
result.AsyncWaitHandle.WaitOne();
int? choice = Guide.EndShowMessageBox(result);
if (choice.HasValue)
messageCommands.ElementAt(choice.Value).Value.Invoke();
}
I get the following exception:
An exception of type 'System.ArgumentException' occurred in Microsoft.Xna.Framework.GamerServices.ni.dll but was not handled in user code
Additional information: The argument is invalid. It must contain between 1 and 2 strings. The strings cannot be null or empty, and must be less than 256 characters long.
By debugging I located the problem to messageCommands.Keys
, because if I call the function with a static array it works just fine.
So what am I doing wrong?
The problem is the number of requested buttons in the call to Guide.BeginShowMessageBox. According to the documentation the maximum number of buttons is two on Windows Phone.