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
Inserting button into XamDataGrid over two data record presenters
posted

Hello!

How can I insert a button into xamDataGrid so it will be like in the picture below? (green button)

I tried adding button to DataRecordPresenter style, but next line is second DataRecordPresenter.

  • 28510
    Offline posted

    Hello Mikhail,

    I have been investigating your requirement, and achieving something like this at the moment would not be a trivial task. It will not be able to be done through a DataRecordPresenter style, unless you were to have a trigger that places half of your circular button in one record and then the other half in the other. This would be limited to the button only spanning two records, though. At the moment, I do have two recommendations, although both will have their difficulties and limitations.

    The first recommendation I can make is that you utilize the Cell Merging feature of the XamDataGrid. This will allow you to define a Field that should have merged cells, where you will have values that are the same next to each other so that the cells merge into one. You can then write a Style and template for MergedCellPresenter and place your button inside. The problem with this is that if the corresponding record is selected, activated, or goes into edit mode, the MergedCellPresenter will go away and the underlying CellValuePresenter will be shown. There is no way to turn this behavior off at the moment. Essentially, the only sure-fire way to keep your button in the grid this way would be to prevent selection, editing, and activation of records, which is not exactly ideal.

    The alternative in this case is to use the WPF Adorner Layer. This also has its drawbacks, though, as you would essentially have to target the grid and then handle scrolling and the scenario when your button would only be partially in view if it is record-specific. The DataRecordPresenter is virtualized and recycled, and so if you targeted it, you would potentially have your adorner button show up in places that you do not really want it to, and this would certainly be messier than targeting the grid, although neither option would be simple.

    If there was a better way to turn off the merged-cell loss on selection/activation or editing, I would definitely recommend that way, but at the moment this functionality does not exist on the grid. If you would like to see this implemented, I would recommend suggesting a new product idea for it at our WPF Ideas Site, here. This will place you in direct communication with our product management teams who plan and prioritize upcoming features and development based on community and user feedback.

    Please let me know if you have any other questions or concerns on this matter.