Hi,
I am facing a problem while renaming a tab in XamDockManager.
Here is what i am doing:-
On doubleclick of tab i am changing the template for TabHeader with a template containing textbox. On Lost focus of textbox i am getting value of textbox and assigning it back to tabheader and changing the Tabheadertemplate to null so as to show tabheader properly.
<DataTemplate x:Key="TabItemHeaderEditWOCloseBtn"> <DockPanel Name="Dock" Height="20" > <TextBox Name="txtTabEdit" Margin="5,2,1,1" IsTabStop="True" TabIndex="0" Text ="{Binding Path=DataContext, RelativeSource ={RelativeSource TemplatedParent}}" LostFocus="txtTabEdit_LostFocus" KeyUp="txtTabEdit_KeyUp" BorderThickness="0"></TextBox> </DockPanel></DataTemplate>
in MouseDoubleClick
currentContentPane.TabHeaderTemplate = this.Resources["TabItemHeaderEditWOCloseBtn"] as DataTemplate;
In LostFocus
currentContentPane.Header = textbox.Text;
Everything works. Only problem is that after a double click foucs is not set on text box I have to click once again on the textbox to edit.
Workarounds I tried
I used following trigger also then also i am not able to do it.
<DataTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=txtTabEdit}"/> </Trigger></DataTemplate.Triggers>
I tried Keyboard.Focus(currentContentPane) after setting the template but i am not getting focus on textbox.
Please guide how i can get focus on TextBox.
Thanks
nihardalai said: used following trigger also then also i am not able to do it. <DataTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=txtTabEdit}"/> </Trigger></DataTemplate.Triggers>
used following trigger also then also i am not able to do it.
Setting the FocusManager.FocusElement has no meaning unless the object on which you set it is a focus scope and even then that just makes it the logically focused element of that focus scope and doesn't necessary change the keyboard focused object.
nihardalai said:I tried Keyboard.Focus(currentContentPane) after setting the template but i am not getting focus on textbox
nihardalai said:Please guide how i can get focus on TextBox