I'm trying to send a Control as a ComandParamter so that I can set focus on it. These controls are in a GridViewColumn HeaderTemplate and tabbing cannot go across headers as far as I can tell. My research has led me to utilize x:reference
because ElementName
fails due to naming scope. The command is properly bound, it does run when I don't bind a CommandParameter.
With the binding shown in xaml below, I receive this error:
Attempt to reference named object(s) 'resourcetypeSrch' which have not yet been defined. Forward references, or references to objects that contain forward references, are not supported on directives other than Key.
How can I bind the ComboBox with x:Name resourcetypeSrch
to the TextBox KeyBinding CommandParameter?
<GridViewColumn DisplayMemberBinding="{Binding Name }">
<GridViewColumn.HeaderTemplate>
<DataTemplate>
<DockPanel>
<TextBlock Text="{StaticResource Name}" />
<TextBox Text="{Binding DataContext.Foo, RelativeSource={RelativeSource AncestorType=Page}}"
Style="{StaticResource SearchBox }" Width="200">
<TextBox.InputBindings>
<KeyBinding Key="Tab"
Command="{Binding DataContext.SearchNavigationCmd, RelativeSource={RelativeSource AncestorType=Page}}"
CommandParameter="{Binding {x:Reference resourcetypeSrch}}"/>
</TextBox.InputBindings>
</TextBox>
</DockPanel>
</DataTemplate>
</GridViewColumn.HeaderTemplate>
</GridViewColumn>
<GridViewColumn Width="350" DisplayMemberBinding="{Binding ResourceTypeLookup.TypeName }">
<GridViewColumn.HeaderTemplate>
<DataTemplate>
<DockPanel>
<TextBlock Text="{StaticResource ResourceType}" />
<ComboBox x:Name="resourcetypeSrch" Width="300" HorizontalAlignment="Left" IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding DataContext.SrchResourceTypeLookups, RelativeSource={RelativeSource AncestorType=Page}, Mode=OneTime}"
DisplayMemberPath="TypeName"
SelectedValuePath="Bar"
SelectedValue="{Binding DataContext.Fizz, RelativeSource={RelativeSource AncestorType=Page}}" >
</ComboBox>
</DockPanel>
</DataTemplate>
</GridViewColumn.HeaderTemplate>
</GridViewColumn>