Hi,
Before overriding the CellValuePresenter, add new row works fine in my grid. After overriding it, it does nothing when entering in the new row. It looks like the new row functions with PART_EditorSite only, but I need to provide a customized control to handle the editing.
Please help to see how to realize this. Thanks!
Hello,Are you using a User/CustomControl inside the ControlTemplate? The PART)EditorSite would be the control that the CVP is looking for, but you can use a Two-Way binding and still get the same thing. Please provide the new modified ControlTemplate so that we can look into it.
Please have a look at the attached sample.The add new row doesn't work in the first grid because of the overridden CVP.Thanks!
Right,
I was playing around with it and it seems that the CellValuePresenter is not interacting with the underlying editor as you and I are expecting :) . This of course leads to the back up plan.
Here are two ways of achieving this:
1. Use Andrew Smith's great blog post on how to host any control in the DataRecord Cell. It works for me perfectly when I need to do something like this.
2. Retemplate the underlying editor - this is some kind of shortcut of the previous approach. I am attaching your sample modified with the second approach.
Thanks Alex,
Does the second approach mean I have to use a "Xam" branded control? I override the CVP because the built-in controls aren't sufficient. I've also considered inheriting ValueEditor, but that would cause inconsistency as the custom controls I'm using is generic company-wide.
The first approach is pretty heavy, and I won't be allowed to use such an amount of code from internet. Is there any alternative to make the new row work? Anything like handling event?
You can use any control that you like, as long as you bind the property that holds the value of the UserControl/CustomControl to the Value property of the underlying editor (the one you retemplate).
The underlying editor is the one you retemplate. You can put any control inside this template and not set PART_EditorSite, as I have done in the sample:
<Style TargetType="{x:Type igEditors:XamTextEditor}" x:Key="EditorStyle">
<Setter Property="EditTemplate">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igEditors:XamTextEditor}">
<StackPanel>
<igEditors:XamComboEditor SelectedItem="{Binding Path=Value, Mode=TwoWay, RelativeSource={x:Static RelativeSource.TemplatedParent}}"
ItemsProvider="{StaticResource provider}">
</igEditors:XamComboEditor>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
As you can see in this code snippet, the style is for XamTextEditor, which is the Editor for that cell, but inside the template, I have put a ComboEditor, which SelectedItem property is bound to the Value property of the XamTextEditor (its templated parent)
Thanks Alex.
"the underlying editor" refers to the control generated in PART_EditorSite by XamDataGrid? How can I bind to that?