Cortana VCD:设置命令将目标导航到子文件夹中的页面

时间:2015-05-28 14:16:24

标签: c# windows-phone-8.1 cortana

我无法通过Cortana启动Windows Phone 8.1应用的特定页面。我已经注册了VCD,并且该命令已被Cortana成功识别。但是当执行命令时,应用程序将启动其默认页面(MainPage.xaml)。我想启动ReportPage.xaml而不是MainPage.xaml。

所有页面都在名为" View"的子文件夹下。 (与创建应用程序时的默认项目模板不同)。

我尝试了几种组合但没有效果:

<Navigate Target="ReportPage.xaml" />
<Navigate Target="View/ReportPage.xaml" />
<Navigate Target="/View/ReportPage.xaml" />
<Navigate Target="ReportPage" />

这是我的VCD:

<?xml version="1.0" encoding="utf-8"?>

<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">
  <CommandSet xml:lang="en-US">
    <CommandPrefix>Traffic Reporter</CommandPrefix>
    <Example>Report a traffic incident</Example>

    <Command Name="ReportIncident">
      <Example>Start reporting a traffic incident</Example>
      <ListenFor>Report</ListenFor>
      <ListenFor>Report an {SortOfIncident}</ListenFor>
      <ListenFor>Report a {SortOfIncident}</ListenFor>
      <Feedback>Starting the report</Feedback>
      <Navigate Target="ReportPage.xaml" />
    </Command>

    <PhraseList Label="SortOfIncident">
      <Item>accident</Item>
      <Item>incident</Item>
      <Item>speed trap</Item>
      <Item>speed check</Item>
    </PhraseList>

  </CommandSet>
</VoiceCommands>

1 个答案:

答案 0 :(得分:2)

假设您使用的是Windows应用商店应用(WinRT): 您是否在 App.OnActivated 方法?

中处理语音激活
protected override void OnActivated(IActivatedEventArgs args)
{
    if (args.Kind == ActivationKind.VoiceCommand)
    {
        Frame rootFrame = Window.Current.Content as Frame;
        VoiceCommandActivatedEventArgs vcArgs = (VoiceCommandActivatedEventArgs)args;

        //check for the command name that launched the app
        string voiceCommandName = vcArgs.Result.RulePath.FirstOrDefault();

        switch (voiceCommandName)
        {
            case "ViewEntry":
                rootFrame.Navigate(typeof(ViewDiaryEntry), vcArgs.Result.Text);
                break;
            case "AddEntry":
            case "EagerEntry":
                rootFrame.Navigate(typeof(AddDiaryEntry), vcArgs.Result.Text);
                break;
        }
    }
}