如何调用Guide.BeginShowMessageBox

How to call Guide.BeginShowMessageBox

我在调用 Guide.BeginShowMessageBox

时遇到问题

这是我的代码:

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();
}

我得到以下异常:

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.

通过调试,我发现问题出在 messageCommands.Keys,因为如果我用静态数组调用该函数,它就可以正常工作。

那我做错了什么?

问题在于调用 Guide.BeginShowMessageBox 时请求的按钮数量。根据文档,Windows Phone.

上的最大按钮数量为两个