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 Elena,
Thank you very much, it is working perfectly :)
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 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.
Thank you for the fast reply :)
Based on the modifications you made in my sample I noticed the "PART_FocusSite" name on the TextBox in the template.As it looked like a generic name, I tried to just change my TextBox name (which was "EditBox") to "Part_FocusSite" and it is now working perfectly.
Thanks a lot!
Thank you for the sample. XamTextEditor control is specially accommodate to work with xamDataGrid, and automatically enters edit mode when you focus it. I have been looking into your sample and I noticed that you set completely new Edit template for the XamTextEditor and this may change some of the default functionality that the editor provides. Based on this I can suggest you use the default EditTemplate of XamTextEditor and modify only these parts from it that you want. You can find the default templates of our controls on your computer in the file: C:\Program Files (x86)\Infragistics\NetAdvantage 2011.2\WPF\DefaultStyles\Editors\EditorsGeneric_Express.xaml .
For further reference please have a look at the attached sample which I modified for you.
If you have any additional questions on this matter please feel free to ask.