2016-06-03 1 views
0

텍스트를 텍스트 상자에 삽입하는 것을 포함하여 Universal Windows App을 만들고 있습니다. 내 애플 리케이션 텍스트 상자에 삽입하는 파일에서 텍스트를 제안 싶습니다. 하지만 그 재산을 찾을 수 없었습니다. XAML 태그를 통해 MainPage.xaml에 텍스트 상자를 추가했습니다. WPF API에는이 작업을위한 속성이 있다고 생각합니다. UWP에서이 작업을 수행 할 수 있는지 확실하지 않습니다.파일에서 C#의 텍스트 상자에 텍스트 제안을 추가 할 수 없습니다.

+0

[AutoSuggestBox] (https://msdn.microsoft.com/en-us/library/windows/apps/mt280217.aspx)와 같은'TextBox' 동작을 만들고 싶습니까? –

+0

@ GraceFeng-MSFT 나는 AutoSuggestBox를 알지 못했다. 그래서, 나는 TextSbox를 AutoSuggestBox처럼 행동하게 만들 생각을했습니다. –

답변

4

UWP 용 AutoSuggestBox 컨트롤을 사용하는 것이 좋습니다. 사용자가 텍스트를 입력하기 시작하면 자동 제안 결과 목록이 자동으로 채워집니다. 결과 목록은 텍스트 입력 상자 위나 아래에 나타날 수 있습니다. 여기

<AutoSuggestBox PlaceholderText="Search" QueryIcon="Find" Width="200" 
      TextChanged="AutoSuggestBox_TextChanged" 
      QuerySubmitted="AutoSuggestBox_QuerySubmitted" 
      SuggestionChosen="AutoSuggestBox_SuggestionChosen"/> 


private void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args) 
{ 
    // Only get results when it was a user typing, 
    // otherwise assume the value got filled in by TextMemberPath 
    // or the handler for SuggestionChosen. 
    if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput) 
    { 
     //Set the ItemsSource to be your filtered dataset 
     //sender.ItemsSource = dataset; 
    } 
} 


private void AutoSuggestBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args) 
{ 
    // Set sender.Text. You can use args.SelectedItem to build your text string. 
} 


private void AutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args) 
{ 
    if (args.ChosenSuggestion != null) 
    { 
     // User selected an item from the suggestion list, take an action on it here. 
    } 
    else 
    { 
     // Use args.QueryText to determine what to do. 
    } 
} 

는 완전한 UI 기본 샘플에 대한 GitHub의의의 repo에 link입니다.

희망이 도움이됩니다.

1

이것은 UAP에는 적용되지 않지만 WPF에서는 "드롭 다운 제안 목록"을 허용하는 트릭이 있습니다. 텍스트 상자를 콤보 상자로 바꾸고 사용자가 입력 할 때 항목을 채울 수 있습니다. 이것은과 같이 일을 바인딩에 의해 달성 될 수있다 :

Text={ Binding Path=meCurrentValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged } 

ItemsSource={Binding Path=meFilteredListOfSuggestions, Mode=TwoWay } 

그런 다음 당신의 ViewModel 내에서 간단히 수행 할 수 있습니다

public string meCurrentValue 
{ 
get { return _mecurrentvalue; } 
set { 
_mecurrentvalue = value; 
updateSuggestionsList(); 
NotifyPropertyChanged("meCurrentValue"); 
NotifyPropertyChanged("meFilteredListOfSuggestions"); // notify that the list was updated 
ComboBox.Open(); // use to open the combobox list 
} 

public List<string> meFilteredListOfSuggestions 
{ 
get{return SuggestionsList.Select(e => e.text.StartsWith(_mecurrentvalue));} 
} 

편집 : TRUE로 콤보 상자의 편집 가능한 값을 설정하는 것을 잊지 마십시오,이 방법을 일반 텍스트 상자처럼 작동합니다.

관련 문제