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
30
XamGrid: edited cell content is cleared when switching tabs in TabControl
posted

Hi there!

I use XamGrid in my application and ran into the issue with cell editing when switching tabs in TabControl. Here is the markup on which the issue is reproduced:

<TabControl Grid.Row="0"
                    Grid.Column="0">
            <TabItem Header="First Tab">
                <ig:XamGrid ItemsSource="{Binding Persons}">
                    <ig:XamGrid.EditingSettings>
                        <ig:EditingSettings AllowEditing="Cell"
                                            IsMouseActionEditingEnabled="DoubleClick"
                                            IsF2EditingEnabled="True" />
                    </ig:XamGrid.EditingSettings>
                    <ig:XamGrid.Columns>
                        <ig:TemplateColumn Key="Name"
                                           HeaderText="Name"
                                           Width="200">
                            <ig:TemplateColumn.ItemTemplate>
                                <DataTemplate DataType="{x:Type local:PersonViewModel}">
                                    <TextBlock DataContext="{Binding}"
                                               Text="{Binding Name}" />
                                </DataTemplate>
                            </ig:TemplateColumn.ItemTemplate>
                            <ig:TemplateColumn.EditorTemplate>
                                <DataTemplate DataType="{x:Type local:PersonViewModel}">
                                    <TextBox DataContext="{Binding}"
                                             Text="{Binding Name}" />
                                </DataTemplate>
                            </ig:TemplateColumn.EditorTemplate>
                        </ig:TemplateColumn>
                    </ig:XamGrid.Columns>
                </ig:XamGrid>
            </TabItem>
            <TabItem Header="Second Tab" />
 </TabControl>

 

The XamGrid is in the TabItem and when I switch to another TabItem the content of the edited cell is cleared. 

Steps to reproduce the issue:

  1. Enter cell edit mode;
  2. Switch to another tab without exiting the edit mode;
  3. Go to the previous tab. 

Actual result: the edited cell is empty.

It seems that the cell DataContext binding is broken after exiting the edit mode and switching the tab.

Is there any workaround for this issue or maybe some XamGrid settings need to be added?

I have attached a test project on which the described issue is reproduced, please let me know if any additional information is required.

Thank you 

Pavel

7026.TestXamGridApplication.zip

Parents Reply
  • 29105
    Offline posted in reply to Pavel M

    Hello Pavel, 

    As explained in Microsoft docs, binding with an empty syntax will result in binding to the entire parent object. In this case the DataTemplate. But you are getting a binding error in the Output window. Can you modify the sample to demonstrate your requirements?

    System.Windows.Data Error: 3 : Cannot find element that provides DataContext. BindingExpression:(no path); DataItem=null; target element is 'TextBlock' (Name=''); target property is 'DataContext' (type 'Object')

Children
No Data