动态填充VoiceCommand PhraseList,找不到Error VoiceCommandSet

时间:2017-12-04 12:47:25

标签: cortana phrases vcd

我正在寻找一种动态填充我的VCD文件的方法。我有Windows文档中的代码段,内容如下:

Windows.ApplicationModel.VoiceCommands.VoiceCommandDefinition.VoiceCommandSet commandSetEnUs;

if (Windows.ApplicationModel.VoiceCommands.VoiceCommandDefinitionManager.
      InstalledCommandSets.TryGetValue(
        "AdventureWorksCommandSet_en-us", out commandSetEnUs))
{
  await commandSetEnUs.SetPhraseListAsync(
    "destination", new string[] {“London”, “Dallas”, “New York”, “Phoenix”});
}

但是,当我将它放入我的App.OnActivated()版本时,Visual Studio会显示一条错误,指出VoiceCommandSet未包含在“Windows.ApplicationModel.VoiceCommands.VoiceCommandDefinition”中。我的问题是:

我是在错误的地方做的吗?你知道任何示例项目,如何正确地做到这一点? (我看了冒险作品,但没有在那边找到这些线条)或者我错过了一些我不知道的参考文献?

1 个答案:

答案 0 :(得分:0)

public async Task UpdateDestinationPhraseList()
        {
            try
            {
                // Update the destination phrase list, so that Cortana voice commands can use destinations added by users.
                // When saving a trip, the UI navigates automatically back to this page, so the phrase list will be
                // updated automatically.
                VoiceCommandDefinition commandDefinitions;

                string countryCode = CultureInfo.CurrentCulture.Name.ToLower();
                if(countryCode.Length == 0)
                {
                    countryCode = "en-us";
                }

                if (VoiceCommandDefinitionManager.InstalledCommandDefinitions.TryGetValue("AdventureWorksCommandSet_" + countryCode, out commandDefinitions))
                {
                    List<string> destinations = new List<string>();
                    foreach (Model.Trip t in store.Trips)
                    {
                        destinations.Add(t.Destination);
                    }

                    await commandDefinitions.SetPhraseListAsync("destination", destinations);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Updating Phrase list for VCDs: " + ex.ToString());
            }
        }