This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I have found the need to change the DisplayTemplate for a DataGridColumn after the column has been displayed (based on a user action). I find that after changing the DisplayTemplate the column is not refreshed using the new template unless I do something like resizing the windows so the column becomes hidden, and then returning to the size. Is there a good way I can force a column to update using the new template in code? |
|
|
Hello Peter In the next nightly build, changing the DisplayTemplate property of a DataGridColumn will cause the column to be refreshed. Jason Fauchelle |
|
|
Hi Jason, Thanks for the quick response--as usual. However, when I tested this I still don't see the refresh occurring. I know the template is getting updated because when I manipulate the window size (narrow then wide) I see the updated template become active. A quick look at the source shows that there is no property-changed callback for the DisplayTemplate property and I don't see a binding to it (thought maybe I'm missing something). Peter |
|
|
Hi Jason, A further update: I have started using the DisplayTemplateSelector to get more flexibility about how individual cells are displayed (as far as I can tell this is the only way to do something like change the FontWeight of an individual cell). In some instances we allow the user to change how data is displayed via a context menu. In my earlier post I had said I need a refresh after changing the DisplayTemplate. However, if I am using a DisplayTemplateSelector (instead of DisplayTemplate) I instead need a way of getting the grid to re-request the templates for a column after something in the DisplayTemplateSelector has changed. I noticed that merely passing the cursor over the cells in a normal column (not an expandable column) causes the templates to be re-requested and cells re-rendered, which seems potentially inefficient (I don't know if the cells are actually re-rendered if the template didn't change). I verified this behavior in the Cell Template Selector demo in the Sample Explorer. Peter |
|
|
Hello Peter My apologies, I had forgotten that you've moved up to 6.0 already. I had made the change in 5.1. This has now been merged into 6.0 and will be available in the next nightly build. TemplateSelectors in WPF aren't designed for dynamic changes in the way you've described. They only select a new template when the container is rendered, or when the Content changes. For this I would recommend re-setting the DisplayTemplate or DisplayTemplateSelector properties in order to make these kind of dynamic changes to the display. Regarding the performance: Under the display/editor template layer, there is a low-detail/high-detail template layer. This is a performance improvement - when cells are simply being displayed, they only show a border and the content. But when the cell is in an editing/mouseover/selected/invalid state, it switches to the high-level template which can contain extra borders. Switching the template like this is far better than having all cells containing several potentially unused Border elements all the time. Jason Fauchelle |
|
|
Hi Jason, Replacing the DisplayTemplate or DisplayTemplateSelector now seems to give me the desired column update. Thanks! I now understand the advantage of switching to the more complex template only when needed. Thanks for the explanation. Peter |
|