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
195
Focus issue with custom EditTemplate
posted

Hello,

i'm experiencing some issues with custom EditTemplate in the XamDataGrid:

my render template is set to a simple TextBlock, and my edit template to a TextBox. The problem is that when I click on a cell (or tab to navigate between cells) I do not get focus into the TextBox although the cell template is switched to the edit template.

 

In the following screenshot we can se that the caret is not visible in the active cell, even if the text is rendered in a textbox (EditTemplate):

 

The following is the xaml code for this FieldSetting:

 <DataPresenter:FieldSettings x:Key="TextBoxEditableField">
 <DataPresenter:FieldSettings.EditorStyle>
  <Style TargetType="{x:Type Editors:XamTextEditor}">

   <!-- Edit template: textBox -->
   <Setter Property="EditTemplate">
    <Setter.Value>
     <ControlTemplate>
      <TextBox x:Name="EditBox" Text="{Binding [This binding works]}" />
     </ControlTemplate>
    </Setter.Value>
   </Setter>

   <!-- Render template: simple textBlock -->
   <Setter Property="Template">
    <Setter.Value>
     <ControlTemplate>
      <TextBlock Text="{Binding [This binding works]}" />
     </ControlTemplate>
    </Setter.Value>
   </Setter>

  </Style>
 
</DataPresenter:FieldSettings.EditorStyle>
</DataPresenter:FieldSettings>

 

I would like to get focus in the "EditBox" TextBox when the edit template is rendered, do you know how I can achieve it?

If needed, enclosed is the sample project I used to render the above screenshot.

Thanks by advance!

Awen

FocusSample.zip
Parents
No Data
Reply
  • 195
    Offline posted

    Hello again,

    I am still experiencing focus issues with custom templates in the dataGrid, this time when using a XamMultiColumnComboEditor. The x:Name="PART_FocusSite" thing works great for a TextBox, but when naming a XamMultiColumnComboEditor this way an exception is raised when the cell goes in edit mode:

    NotSupportedException "Can only name a TextBox as 'PART_FocusSite', not a XamMultiColumnComboEditor"

    Please find enclosed the updated sample project to help with your tests an research. In the "styles.xaml" file, at line 18 you can find the x:Name attribute working for the TextBox (if removed, the TextBox does not get the focus); at line 47 you can find the XamMulticolumnComboEditor markup, if you add the x:Name="PART_FocusSite" attribute the application will crash on combo focus.

    Regards,

    Awen

    FocusSample.zip
Children