WPF Toolkit에서 AutoCompleteBox
을 사용하여 검색 필드를 작성하려고합니다. AutoCompleteBox의 Text 속성은 ViewModel
에있는 INotifyPropertyChanged
을 구현하는 속성에 바인딩됩니다. 속성이 변경되면 사용자에게 표시 할 새 제안을 가져옵니다.AutoCompleteBox에서 키보드 탐색으로 SelectionChanged 이벤트가 발생하지 않도록하는 방법은 무엇입니까?
사용자가 커서 키를 사용하기 전에 화살표 키를 사용하여 자동 완성 제안 목록을 검색하면 커서가 팝업으로 이동하고 SelectionChanged
이 실행되고 텍스트 필드가 새로운 값을 얻으며 자동 완성 제안은 다시 수집됩니다. 또한 검색을 시작하기 위해 SelectionChanged
이벤트를 사용하려는 나의 욕구를 저해합니다.
키보드 탐색에서 SelectionChanged 이벤트가 실행되지 않도록 할 수있는 방법이 있습니까?
다음은 설정 방법입니다.
<sc:SearchField x:Name="SearchField" DataContext="{Binding SearchBoxVm}" Text="{Binding Query, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding QuerySuggestions, UpdateSourceTrigger=PropertyChanged}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" IsTextCompletionEnabled="False" Margin="54,10,117,67" Grid.RowSpan="2" BorderThickness="0" FontSize="14" PreviewKeyUp="searchField_OnKeyup" Foreground="{Binding Foreground, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" FontStyle="{Binding QueryFont, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >
</sc:SearchField>
뷰 모델 :
void GetQuerySuggestions()
{
if (!string.IsNullOrEmpty(Query) && !Query.Equals(DEFAULT_TEXT))
{
QueryFont = FontStyles.Normal;
Foreground = Brushes.Black;
QuerySuggestions = SearchAssistant.GetQueryRecommendations(_query);
}
}
public string _query = DEFAULT_TEXT;
public string Query
{
get
{
return _query;
}
set
{
_query = value;
GetQuerySuggestions();
NotifyPropertyChanged("Query");
}
}
List<string> querySuggestions = new List<string>();
public List<string> QuerySuggestions
{
get { return querySuggestions; }
set
{
querySuggestions = value;
NotifyPropertyChanged("QuerySuggestions");
}
}
SearchField sc:SearchField
단지 내가 SelectAll()
XAML과 같은 함수를 호출 할 수있는 AutoCompleteBox
에 TextBox
속성에 액세스 할 수있는 방법을 제공합니다 AutoCompleteBox
의 서브 클래스 참고 하위 클래스 :
public class SearchField : AutoCompleteBox
{
public TextBox TextBox
{
get
{
return (this.GetTemplateChild("Text") as TextBox);
}
}
}