does anyone know how to reuse a fieldlayout across multiple grids? can someone post an example?
right now i have multple grids that have very similar behavior and have very similar field layouts. i have managed to push the logic up into a base class, but xaml cannot be inherited (as far as i know). so at the moment i am copying the same field layouts over and over again across multiple grids. this seems like a poor architecture, and it is too cumbersome to maintain over time.
i am speculating that there may be a way to put a fieldlayout into a resourcedictionary, reference the fieldlayout as a dynamicresource in the xamdatagrid, save the resourcedictionary as a xaml file, read the resourcedictionary in at runtime, instantiate a MergedDictionaries, and using this pattern, reuse the same fieldlayout across multiple xamDataGrids.
at this point i can't even figure out how to reference a fieldlayout from the resources.
does anyone know how to reuse a fieldlayout across multiple grids?
can someone post an example of putting a fieldlayout into the resources area and referencing that resource in the xamdatagrid? or post some other pattern i haven't thought of? thanks. -g
Well,
As the exception implies, you cannot move the FieldLayout to another Presenter. To the best of my knowledge the way to do this is by Save/Load customizations, deep copy or manually.
Thank you, Alex. When I attempt this with a complex field layout, I found that it is not persisting styles.
I came up with a pattern that is mostly working. I am having trouble with at least one thing right now. Maybe you can help me. What I did was I put the field layouts into a resource dictionary. One thing though. The different field layouts are about 95% identical. The problem I am having is with the 5% difference.
For example, one field layout has eight fields in common with another, but there are 2 or 3 fields that one layout has that another one does not, and vice-verse. I got it working by putting all fields in all field layouts, and then hiding the ones I don't want the user to see in a particular grid.
But this is not ideal. What I would like to do is to define the fields themselves in the resource dictionary, styles and all, and then add them to a particular field layout dynamically in code. I almost got this working, but I am having at least this one obstacle.
When I try to add the field dynamically, I get the error:
"Field can not be moved to another collection."
I noted another post from someone else on this, here:
http://news.infragistics.com/forums/p/16310/105493.aspx
But the solution was not given. Do you have any ideas?
Hello Geoffrey,
You can use the Save/LoadCustomizations method to achieve this. I am attaching a sample with this implemented.
Rearrange some fields on the left XamDataGrid and click the Save Button. Then click the Load button and these changed will be applied to the right XamDataGrid.
Hope this helps.