<TextBox Width="120" Margin="20,0" HorizontalAlignment="Left"
KeyDown="{x:Bind ViewModel.AddNewTag}"
PlaceholderText="Add New Tag"
Text="{x:Bind ViewModel.NewTagToAdd, Mode=TwoWay}" />
public void AddNewTag(object sender, KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter)
{
var newTag = ((TextBox)sender).Text;
if (NewTagDoesNotExistInCurrentLists(newTag))
{
var tagDTO = new TagDTO { UserName = UserName, TagName = newTag };
NewTagToAdd = null;
TagsAvailableForSelecting.Add(tagDTO);
TagsAvailableForSelecting.Sort(x => x.TagName, true);
}
}
}
当我在文本框中键入一个单词并按 Enter 键时,该方法会被调用两次。使用模板 10。
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0",
"Microsoft.Xaml.Behaviors.Uwp.Managed": "1.1.0",
"Newtonsoft.Json": "8.0.3",
"Template10": "1.1.*",
"WindowsAzure.Storage": "7.1.2"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}