我目前在我的Silverlight应用程序中实现了Cortana.语音命令存储在CortanaCommands.xml中,这里是代码:
<?xml version="1.0" encoding="utf-8"?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">
<CommandSet xml:lang="en-US">
<CommandPrefix>Dr. Bailey</CommandPrefix>
<Example> Open app to take dictation </Example>
<Command Name="Text">
<Example> Is it going to rain? </Example>
<ListenFor> [create] {dictation} </ListenFor>
<Feedback> "" </Feedback>
<Navigate Target="/Views/CortanaText.xaml" />
</Command>
<PhraseTopic Label="dictation" Scenario="Dictation">
<Subject> Cal 123 </Subject>
</PhraseTopic>
</CommandSet>
</VoiceCommands>"
Run Code Online (Sandbox Code Playgroud)
在这个例子中,如果用户部署Cortana并说"Bailey博士,它会下雨吗?",那么应用程序导航到CortanaText.xaml.这被硬编码到XML中,我希望用户能够自定义其命令前缀及其命令.
通过使用2个文本框,我在C#中编码了一个包含整个XML的字符串,但是从包含新命令前缀和命令的文本框中插入选项.这个字符串叫做cortanaXMLstring.使用新字符串覆盖CortanaCommands.xml中现有代码的最佳方法是什么?我认为这比修改现有XML的2个不同区域更容易.我还认为可以删除CortanaCommands.xml(使用c#代码),然后通过简单地插入字符串再次创建该XML,因为字符串包含XML所需的所有文本?或者,有关如何在XML中修改这两个字段的任何其他建议吗?这是命令前缀和命令示例.感谢您提供的任何帮助!