I have attached a watered down sample of a condition that exists in our product. We are using the ControlHostEditor in DataTemplates applied to XamDataGrids to host our own custom controls. (The Custom control in the sample is a trivial example.)
The ControlHostEditor works well with the exception of handling Drag and Drop events. The issue seems to be centered around the Edit/Render Templates concept. Drop actions do not apply to the underlying DataSource unless the Cell is in Edit mode. This is counter-intuitive to end-users and presents a Usability issue. I need to fix this.
The problem is exhaserbated by allowing the Drop when the target cell is in Render mode. The droped data will appear. However, subsequent focus/loss of focus will cause the Cell to enter/exit Edit mode. Upon which the dropped data is lost.
So I need a way to update the underlying DataSource while in Edit Mode, but only during a Drop event. Got any ideas on how to resolve this? My attempts so far have not worked.
To Duplicate the Behavior:
1. Run the attached project.
2. Open a word document
3. Type in a few words.
4. Drag and drop a word from the Word Doc into any Cell in the sample application other than the Cell with focus.
5. Note that the text is dropped into the cell.
6. Click into the Cell’s Textbox – setting the Edit mode.
7. Click into any other Cell, leaving Edit mode.
8. Notice that the dropped data is gone.
Hello,
I am glad I have manage to assist you with solving this issue.
Thank you for choosing Infragistics components.
Sincerely,
Ekaterina
Developer Support Engineer
Infragistics, Inc.
www.infragistics.com/support
Setting the EditTemplate to the Template property is what was suggested in the original source code provided by an Infragistics blog here:
http://blogs.infragistics.com/blogs/andrew_smith/archive/2009/03/27/hosting-wpf-controls-in-a-xamdatagrid-cell.aspx
<igDP:UnboundField Name="slider" DataType="{x:Type sys:Double}">
<igDP:Field.Settings>
<igDP:FieldSettings>
<igDP:FieldSettings.EditorStyle>
<Style TargetType="{x:Type igSamples:ControlHostEditor}">
<Setter Property="ValueType" Value="{x:Type sys:Double}" />
<!-- Provide a custom edit data template that uses a slider -->
<Setter Property="EditDataTemplate" Value="{StaticResource sliderTemplate}" />
<!-- Since we want to use the slider when in edit mode or not, we will
use the edit template as the render template. Note, even if you set the
FieldSettings's AllowEdit to false, this would still allow manipulation
of the value. -->
<Setter Property="Template" Value="{Binding Path=EditTemplate, RelativeSource={RelativeSource Self}}" />
</Style>
</igDP:FieldSettings.EditorStyle>
</igDP:FieldSettings>
</igDP:Field.Settings>
</igDP:UnboundField>
Your solution fixed the issue if we use the Default Render Template, but not if we want to use a different control for the Render Template. In that case, it turns out we have to override OnPreviewDragEnter instead of OnDragEnter. For whatever reason, when using a RenderTemplate and EditTemplate, the OnDragEnter event was not firing. This solves our problem. Thanks for pointing me in the right direction.
You may consider updating the source in the blog entry cited above to spare the next guy some headaches. I spent a lot of time just isolating the issue.
Thanks.
I have been investigating your issue and after debugging the sample the reason for this behavior seems to be in the templates. I have notice that you are setting the EditTemplate to the Template property, and I am not sure why. Also the switch between the Render and Edit templates was not working properly. When I have comment out the following lines:
<!--<Setter Property="RenderDataTemplate" Value="{StaticResource textRenderTemplate}" />-->
<!--<Setter Property="Template" Value="{Binding Path=EditTemplate, RelativeSource={RelativeSource Self}}" />-->
And I have handled the ControlHOstEditor’s OnDragEnter, forcing the control to enter Edit mode, so the issue was solved.
Please take a look at your updated sample and in case of future concerns, do not hesitate to ask me.