[英]focusing on a control before saving
所以我們有一個應用程序,我們正在使用一個自動建議框,用戶開始輸入這個詞,直到他們選擇他們想要的詞。 一旦他們點擊那個詞,它就會進入一個文本框。
我發現當我選擇單詞並單擊我的保存按鈕時,它不會保存我的選擇。 如果我在點擊保存之前在文本框中單擊,它只會保存我的選擇。 我想避免讓用戶在保存之前必須在文本框中單擊,所以我想將焦點放在文本框上。 有沒有一種簡單的襯墊可以實現這一點?
這是下面的方法,在選擇單詞后填充文本框:
'''
private void StructureAutoSuggest_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
{
if (args.ChosenSuggestion != null && args.ChosenSuggestion.ToString() != "No results found" && sender.Text != string.Empty)
{
strucType.Text = args.ChosenSuggestion.ToString();
strucType.Focus();
}
else
{
//Reset litho box
strucType.Text = string.Empty;
}
//Update list that are bound to lithology selection
strucViewModel.InitFill2ndRound(strucType.Text);
}
'''
'''
<AutoSuggestBox x:Name="StructureAutoSuggest" x:Uid="StructureAutoSuggest"
RelativePanel.RightOf="structTypeSearch"
RelativePanel.AlignBottomWith="structTypeSearch"
TextChanged="StructureAutoSuggest_TextChanged"
QuerySubmitted="StructureAutoSuggest_QuerySubmitted"
Width="300"/>
<TextBox x:Name="strucType" Header="" x:Uid="StructDialogType"
RelativePanel.Below="StructureAutoSuggest" RelativePanel.RightOf="structTypeSearch"
Width="Auto" Style="{ThemeResource TextboxMandatoryField}" IsReadOnly="True" FontWeight="Bold"
Text ="{x:Bind strucViewModel.StructClassTypeDetail, Mode=TwoWay}"
TextChanging="StrucType_TextChanging" />
'''
嘗試將此添加到您的AutoSuggestBox
的QuerySubmitted
事件:
StructureAutoSuggest.Focus(FocusState.Programmatic);
不過,很可能其他地方存在問題,就像 Nico Zhu 在這里建議的那樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.