Hello,
On tabbing into the second cell of the XamDataGrid i want that the element which is in the cell should get focus and not the outer cell. I am using ValueEditor in the style. I also tried CellValuePresenter but still the focus remains on the outer cell and not on the element.
I have developed a sample application. Attached is the same. Please have a look and suggest what can be done.
https://drive.google.com/open?id=1BdVbm2860IsjWtg1F4e7aMqQbR6_MbKz
Regards,
Abdi
Hello Abdi,
I have been investigating into the sample project you have provided, and I am under the impression that in the sample project, you are trying to have the Button be focused. If my impression on this is correct, I have a couple of recommendations for you on this matter.
My best recommendation on this is to utilize a TemplateField and a DisplayTemplate for that TemplateField rather than re-templating the ValueEditor element for your Field to place a Button inside. A TemplateField was built so that you can effectively put any element you want inside without needing to re-template elements of the grid. I have tried this using the sample project and the Button focuses automatically using this method. You can read about this method at this documentation article.
I am attaching a sample project to demonstrate this, along with a workaround using the ValueEditor re-templating using the CellActivated event of the grid, if for some reason you are looking to continue with that instead of using the TemplateField. I would highly recommend using a TemplateField for this, though.
Please let me know if you have any other questions or concerns on this matter.
6663.WpfApp2.zip
Thanks Andrew for your reply.
Your solution of Template does work but one other issue which i am facing is still not solved. I can post another question in the forum for this but i request you to look into it in this here itself so that i don't have to explain all the things again to anyone I have marked your previous reply as verified.
I want to show the message on click of the button on the single click. That is if the row in which we are clicking the button is not in focus, then on the single click it should show the message. What i mean to say is that click of button should execute on the single click.
Now there is a property called "CellClickAction" present in TemplateField.Setttings. When it is set to "SelectCell" then the above problem gets addressed but then the focus on tab does not go to the element. When it is set to "EnterEditModeIfAllowed" then the focus goes to the element on tab but single click stops working.
Is this the default behavior of XamDataGrid? Below is the link which has some code i explained above as commented.
https://drive.google.com/open?id=1oyNUe1hz1qdUqABS_RRNdpFk_-xNa-IF
Thanks,
I believe that what is happening with the new issue in this case is that when your CellClickAction is in “EnterEditModeIfAllowed” property is set, the TemplateField will try to look for an EditTemplate, and if it doesn’t find one, it will simply select the cell on click, and I believe this cell selection is essentially “eating” the Button click in this case. The “SelectCell” option is selecting the cell, but is allowing the click to get through to the Button. I do believe this is likely the default behavior of the XamDataGrid, as the TemplateField behaves a little bit differently than the other fields in the grid.
In order to focus the Button with the “SelectCell” mode, I would simply recommend utilizing the CellActivated method that was provided in the previously attached project, in which you can programmatically focus the button within the cell on activation.
Hello Andrew,
Thanks for the reply.
It's not just TemplateField for which this issue is happening but it is applicable to any "Field" used in xamdatagrid. As you said that this is default behavior of XamDatagrid, there is hardly anything else we can think of to do.
Yes I can use CellActivated but then I have several links in the several grids. Not only it would be a costly affair to use this event but also it would be difficult to write a generic code for them (without using Field Names).
Can we still think of any other approach or solution so that both click as well as tab focus works together?
Regards,Abdi
I have been investigating into this behavior a bit further, and I have found that it is the CellValuePresenter, and effectively the ValueEditor that exists inside that is “eating” the event and so the Click event is never happening in this case. In the case of the TemplateField, the ValueEditor derivation that is inside of the cell is a TemplateEditor.
I have been doing some experimentation, and I would like to recommend another way in this case. I have been trying a couple of things using CellValuePresenter styles, and in setting the ContentTemplate to a new DataTemplate containing a Button (much like the one in the TemplateField) and then setting it to be the CellValuePresenterStyle of a Field, I am able to see that the Button gets focus and can be clicked normally. Something about this appears to be getting around the CellValuePresenter eating the event, although I’m not entirely sure what at the moment.
I am attaching a modified version of the sample project you sent to demonstrate. I hope this helps you.
4705.WpfApp2.zip
Hi Andrew,
I tried running your code but getting some infragistic DLL version error.
I copied your cellvaluepresenter changes in my solution and ran it. But still on tab, focus is on outer cell and not button.
Below is the link. Can you please look n suggest if missed something.
I apologize, I hadn’t realized that it was actually the CellValuePresenter taking focus again in this case. I suppose there was a check that I was missing in that I suppose I hadn’t checked the enter key.
I have been looking into this a bit further, and it is essentially as I had expected – the CellValuePresenter is stealing focus in this case. The Button is not an “editable” element, and so it’s not getting the focus like a normal TextBox or other ValueEditor control would, and I believe this is expected.
Locally, I have also recently tried a full re-template of the CellValuePresenter – essentially making that element just a Button control, but even then, the CellValuePresenter still takes focus when tabbed to, although you can still activate the button’s click event on a single click.
I think the best catch-all solution that I can recommend in this case is again, to utilize the CellActivated event that I had recommended previously. You had mentioned that you believe this will be difficult to do without using Field names, although I don’t really think this is the case. As long as you name your Button in your Field “focusButton,” you actually don’t need the check for e.Cell.Field.Name. I simply put that there, because there is no check for btn != null after the call to Infragistics.Windows.Utilities.GetDescendantFromName, as it would never be null in the case of the “ButtonField” Field. In your case, to make this generic, you could check for btn != null. If btn is null as a descendant of the CellValuePresenter in the CellActivated event, that simply means that there is no Button in that cell and the newly activated cell belongs to a different Field.