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
1470
AddNewRecord problem
posted

Hi there

We got a problem with the AddNewRecord funtionality of the xamDataGrid.

On some cells, we're showing a button to the user. When the user clicks the button, another window is shown with whatever content. Then the user can select an option in this window, and the value is getting written back to the underlying dataitem. Everything is working fine on a record, where the underlying dataitem is already there. But when the user is in the AddNew-Row, and he starts typing or directly clicks the button, in this specific cell with the button, the xamDataGrid is not instanciating a new underlying dataitem. Therefore, our application does not work as expected.

I have created a small sample application, where you can exactly see, what our problem is.

The underlying dataitem 'Entry' has 3 properties. 'Age', 'LastName' and 'Name'. On 'Age' and 'LastName' everything is working as expected. But on 'Name' (where i have attached the Style for the CellValuePresenter), the constructor is not getting called, when the user starts typing or is clicking the button.

Can you help me with that? We need the same behavior, which a cell has without that style when a user starts typing. Also the same behavior, when the user clicks the button, as he would start typing.

XamDataGrid_AddNew_Test01.zip
Parents
No Data
Reply
  • 34510
    Offline posted

    Hi Christian,

    The Entry class is being instantiated when the cell editor value changes.  There is a specific editor type (ValueEditor) that the cell is looking for and currently your CellValuePresenter style template doesn't have this editor.  So the simplest thing you could do is add the appropriate ContentPresenter with the correct x:Name so that the cell can find it and insert the desired ValueEditor.  Replace your TextBox with this:

    <ContentPresenter x:Name="PART_EditorSite" Grid.Row="0"
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                        Margin="{TemplateBinding Padding}"
                        Style="{TemplateBinding ForegroundStyle}"/>

    You can still have all the other custom stuff inside the CellValuePresenter template, but our code is specifically looking for a PART_EditorSite so it can insert a ValueEditor (XamTextEditor, XamNumericEditor, etc).

    This should give you the same behavior as the other cells that don't have any styling.

Children