简体   繁体   English

动态填充VoiceCommand PhraseList,未发现错误VoiceCommandSet

[英]dynamically populate VoiceCommand PhraseList, Error VoiceCommandSet not found

I am looking for a way to dynamically populate my VCD file. 我正在寻找一种动态填充VCD文件的方法。 I have a Code snippet from the Windows documentation that reads as follows: 我有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”});
}

But, when I put this into my version of App.OnActivated() Visual Studio shows an error saying that VoiceCommandSet is not contained in "Windows.ApplicationModel.VoiceCommands.VoiceCommandDefinition". 但是,当我将其放入我的App.OnActivated()版本中时,Visual Studio会显示一个错误,指出“ Windows.ApplicationModel.VoiceCommands.VoiceCommandDefinition”中不包含VoiceCommandSet。 My questions are: 我的问题是:

Am I doing that in the wrong place? 我在错误的地方吗? Do you know any example projects, that show how to do this properly? 您是否知道任何示例项目,说明如何正确执行此操作? (I looked into Adventure Works, but didn't find these lines over there) Or am I missing some references, that I'm not aware of? (我调查了Adventure Works,但是没有在那找到这些行)还是我缺少一些我不知道的参考?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM