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
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,
Hello Awen,
I have been looking into your sample and I can suggest you handle the Loaded event of the XamMultiColumnCombo and manually force the editor to enter the edit mode. You can achieve this by setting the following style in your main window:
<Style TargetType="{x:Type ig:XamMultiColumnComboEditor}"> <EventSetter Event="Loaded" Handler="XamMultiColumnComboEditor_Loaded"/> </Style>
and handle the event as follows:
private void XamMultiColumnComboEditor_Loaded(object sender, RoutedEventArgs e) { SpecializedTextBox txt = Utilities.GetDescendantFromType(sender as DependencyObject, typeof(SpecializedTextBox), false) as SpecializedTextBox; txt.SelectAll(); txt.Focus(); }
If you need any additional assistance with this approach please do not hesitate to ask.
Hello Elena,
Thank you very much, it is working perfectly :)