Does the MessageDialog class for UWP applications have three buttons on a mobile device?

I am creating a simple program to read a text file on a Windows Phone. I decided to make this a universal Windows platform (UWP).

In the application, I have a very simple MessageDialog with three parameters: Yes, No, Cancel. It works great on the desktop and in the simulator. However, when testing with the actual device, the method ShowAsyncfails with the message: "The value does not fall into the expected range."

This only happens if more than two commands are written in the dialog box. Does the class MessageDialogreally support up to three commands - as the documentation suggests, or does this only apply to UWP applications running on desktop devices?

+4
source share
2 answers

At the moment, the documents have a clear statement:

There is a command bar in the dialog box, which can support up to 3 commands in desktop applications or 2 commands in mobile applications.

It’s sad, but true: there are only two teams on mobile phones. Need more? Use ContentDialog instead.

0
source

, Mobile ( API ).

Mobile, Back, null, ( , ):

async Task Test()
{
  const int YES = 1;
  const int NO = 2;
  const int CANCEL = 3;

  var dialog = new MessageDialog("test");
  dialog.Commands.Add(new UICommand { Label = "yes", Id = YES });
  dialog.Commands.Add(new UICommand { Label = "no", Id = NO });

  // Ugly hack; not really how it supposed to be used.
  // TODO: Revisit if MessageDialog API is updated in future release
  var deviceFamily = AnalyticsInfo.VersionInfo.DeviceFamily;
  if (deviceFamily.Contains("Desktop"))
  {
    dialog.Commands.Add(new UICommand { Label = "cancel", Id = CANCEL });
  }
  // Maybe Xbox 'B' button works, but I don't know so best to not do anything
  else if (!deviceFamily.Contains("Mobile"))
  {
    throw new Exception("Don't know how to show dialog for device "
      + deviceFamily);
  }

  // Will return null if you press Back on Mobile
  var result = await dialog.ShowAsync();

  // C# 6 syntactic sugar to avoid some null checks
  var id = (int)(result?.Id ?? CANCEL);

  Debug.WriteLine("You chose {0}", id);
}
0

Source: https://habr.com/ru/post/1628711/


All Articles