Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
170
Renaming of Tab for DockManager.
posted

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

  • 54937
    Offline posted

    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>

     

    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

    Setting focus to the ContentPane would just put keyboard focus on the ContentPane itself - it would not know anything about the pane tab item or that that tab item might contain an element that you want it to transfer focus to.

    nihardalai said:
    Please guide how i can get focus on TextBox

      When you change the template of an object that does not synchronously create that element. It will likely be created during the next measure/arrange pass.  Maybe what you need to do is to call UpdateLayout after you change the template so that the template is applied and the elements within it are created. Then find the textbox within the template of the tab item and set focus to it.