Have a ListView with a template selector
What I need is for the TextBox named tbStringSVfieldValue to get focus when this ListBoxItem gets selected (clicked or arrow) ?
<DataTemplate x:Key="fieldTemplateStringSV">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="4*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4" Text="Enter key to save. Tab to get the first match from existing values. Value is only committed on Enter key." VerticalAlignment="Center" Style="{StaticResource Italic}"/>
<ScrollViewer Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" VerticalContentAlignment="Stretch"
HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<TextBox x:Name="tbStringSVfieldValue" BorderBrush="SteelBlue" BorderThickness="2" TextWrapping="Wrap"
Text="{Binding Path=FieldValue, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource stringTabConverter}}"
Validation.Error="Validataion_Error" AcceptsReturn="True" AcceptsTab="True"
PreviewKeyDown="tbStringSVfieldValue_PreviewKeyDown"/>
<!--, Converter={StaticResource stringTabConverter}-->
</ScrollViewer>
<TextBlock Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4" Text="Existing values. Click to populate the value above." VerticalAlignment="Center" Style="{StaticResource Italic}"/>
<ListBox Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="4" Height="150" Margin="5,2,0,0" x:Name="lbSVtextPast" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.IsDeferredScrollingEnabled="True"
FontStyle="Normal"
ItemsSource="{Binding Path=PastEntries}" SelectedItem="{Binding Path=SelectedPastEntry}"
SelectionChanged="lbSVtextPastSelectionChanged"/>
</Grid>
</DataTemplate>
above I tried
<Grid FocusManager.FocusedElement="{Binding ElementName=svTBsv}">
<ScrollViewer x:Name="svTBsv" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" VerticalContentAlignment="Stretch"
HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto"
FocusManager.FocusedElement="{Binding ElementName=tbStringSVfieldValue}">
<TextBox x:Name="tbStringSVfieldValue" BorderBrush="SteelBlue"
note below does NOT work
this.tbStringSVfieldValueStringSV is null
it only exists in the template
need to somehow get access to the correct template
note there will be more than one DataTemplate x:Key="fieldTemplateStringSV" in the ListBox
private void lbCurDocFields_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
MessageBox.Show("lbCurDocFields_SelectionChanged " + sender.GetType().ToString());
if (sender is ListBox)
{
ListBox lb = (ListBox)sender;
//lb.Template.VisualTree;
MessageBox.Show(lb.Template.ToString());
if (lb.SelectedItem != null)
{
MessageBox.Show(lb.SelectedItem.GetType().ToString());
if (lb.SelectedItem is GabeLib.DocFieldStringSV)
{
if (this.tbStringSVfieldValueStringSV != null)
this.tbStringSVfieldValueStringSV.Focus();
}