Hi,
I'm trying to build a custom control that is a textbox that displays recent similar values. I've seen a couple approaches to this, but not with XAML. I'm pretty new to custom controls, so this may be a simple question, but I haven't found an answer yet.
The problem I'm trying to solve is how to capture the down-arrow key and transfer focus from the textbox to the popup with results.
<ScrollViewer x:Name="PART_ContentHost" Grid.Column="0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /><Popup><Popup.Style><Style TargetType="Popup"><Setter Property="IsOpen" Value="True"/><Style.Triggers><DataTrigger Binding="{Binding History.Matches, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:SearchTextBox}}}" Value="{x:Null}"><Setter Property="IsOpen" Value="False"/></DataTrigger><DataTrigger Binding="{Binding IsFocused, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:SearchTextBox}}}" Value="False"><Setter Property="IsOpen" Value="False"/></DataTrigger><DataTrigger Binding="{Binding HasText, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:SearchTextBox}}}" Value="False"><Setter Property="IsOpen" Value="False"/></DataTrigger></Style.Triggers></Style></Popup.Style><ListBox Padding="2" x:Name="ctlMatchesListBox" ItemsSource="{Binding History.Matches, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:SearchTextBox}}}" /></Popup>
The ctlMatchesListBox isn't available in the code-behind, and I'm not sure how to "find" the ListBox to set the selected item to the the first on the list in the event handler for the down arrow. What is the "correct" way to transfer focus here?
Thanks,
Terry