Code for Decision
What you can do is sign up for an event AutoSuggestBox
GotFocus
.
<AutoSuggestBox x:Name="autoSuggestBox" GotFocus="autoSuggestBox_GotFocus" />
ListView.ContainerFromItem
ListViewItem
IsSelected
true
.
private void autoSuggestBox_GotFocus(object sender, RoutedEventArgs e)
{
var item = ((AutoSuggestBox)sender).DataContext;
var container = (ListViewItem)DirectionEntryList.ContainerFromItem(item);
container.IsSelected = true;
}
( )
, Behavior
.
-, SDK (XAML) ( 12.0 ) > Universal Windows > Extensions.
, DirectionEntryList
GotFocus
, .
public class SelectListViewItemWhenElementGotFocusBehavior : DependencyObject, IBehavior
{
private UIElement _element;
public DependencyObject AssociatedObject { get; set; }
#region ListView reference
public ListView ListView
{
get { return (ListView)GetValue(ListViewProperty); }
set { SetValue(ListViewProperty, value); }
}
public static readonly DependencyProperty ListViewProperty =
DependencyProperty.Register("ListView", typeof(ListView), typeof(SelectListViewItemWhenElementGotFocusBehavior), new PropertyMetadata(null));
#endregion
public void Attach(DependencyObject associatedObject)
{
AssociatedObject = associatedObject;
_element = this.AssociatedObject as UIElement;
if (_element != null)
{
_element.GotFocus += OnElementGotFocus;
}
}
private void OnElementGotFocus(object sender, RoutedEventArgs e)
{
var item = ((AutoSuggestBox)sender).DataContext;
var container = (ListViewItem)ListView.ContainerFromItem(item);
container.IsSelected = true;
}
public void Detach()
{
if (_element != null)
{
_element.GotFocus += OnElementGotFocus;
}
}
}
, Blend, DataTemplate
AutoSuggestBox
.
<AutoSuggestBox x:Name="autoSuggestBox">
<Interactivity:Interaction.Behaviors>
<local:SelectListViewItemWhenElementGotFocusBehavior ListView="{Binding ElementName=DirectionEntryList}" />
</Interactivity:Interaction.Behaviors>
</AutoSuggestBox>