I have an issue where I have a Three tier hierarchy and a two tier hierarchy. The field layouts are described for each tier, However one FieldLayout is repeated in both hierarchys. This causes the FieldLayout display to only work for one: either the 3 tier hierarchy or the two tier hierarchy . Never both of them at the same time.
So my question is can you have a FieldLayout with two different ParentFieldLayoutKey
Current solution is to describe the same FieldLayout twice, giving each FieldLayout a different ParentFieldLayoutKey. which works:
<DataPresenter:FieldLayout Key="DadModel"> <!-- DadModel can be two different classes DadModel or GroupModel --> ... <DataPresenter:Field Name="GroupComponentModels" /> <DataPresenter:Field Name="SonModels" /> </DataPresenter:FieldLayout> <DataPresenter:FieldLayout Key="GroupComponentModel"> ... <DataPresenter:Field Name="SonModels" /> </DataPresenter:FieldLayout> <DataPresenter:FieldLayout Key="SonModel" ParentFieldLayoutKey="DadModel"> ... </DataPresenter:FieldLayout> <DataPresenter:FieldLayout Key="SonModel" ParentFieldLayoutKey="GroupComponentModel"> ... </DataPresenter:FieldLayout> <!-- All the classes --> <!-- Class DadBase, Class DadModel:DadBase, Class GroupModel:DadBase, Class GroupComponentModel:TModel, Class SonModel -->
However I don't like this as the FieldLayout has to be repeated twice. Duplicate xaml, Is there a better solution ?
Hello Azim,
Thank you for contacting Infragistics. I believe what you are looking to do requires hooking AssigningFieldLayoutToItem event.
Are you trying to assign /toggle between different layouts at runtime for the same grid or assign a single/multiple layout to multiple grids?
To ensure we are in sync I recommend checking out our online documentation for defining hierarchical layouts in XAML. Assigining a fieldlayout at runtime. You can simply toggle the visibility of the fields you want instead which is easier to manage in my opinion than multiple layouts. If you want to assign different layouts you need to hook the grids AssigningFieldLayoutToItem event. Example
Hi Michael,
So its a single grid with multiple Hierarchy layouts co-existing. The grid will have both layouts in the grid at the same time:Dad -> SonsGroupedDad -> Component Dad -> Sons
So the grid could be made up of many dads and many grouped dads:Dad -> SonsDad -> SonsDad -> SonsDad -> SonsGroupedDad -> Component Dad -> SonsGroupedDad -> Component Dad -> Sons
Without having two FieldLayouts for SonModel - only one of the Hierarchy layout works. Its either works for "Dad -> Sons" or "GroupedDad -> Component Dad -> Sons". Where the Sons grid displays nothing.
Obviously having two field layouts and explicitly adding ParentFieldLayoutKey resolves the issue. However my issue with this is that this create duplicate Xaml.
Maybe Helpful(?): The problem might be arising because of Inheritance, Component Dad is derived form Dad, so it would make sense to think "Dad -> Sons" and "Component Dad -> Sons" are the same. However the Hierarchy layout misses this fact.
Adding a ParentFieldLayoutKey resolves the issue with a "Sons" layout in XAML? I believe this is because you are manually defining your layouts and with out it the grid is being told nothing to render.
Do you have an example? sample solution to send
Sorry don't have an sample solution as I would have to rewrite it all. As you could guess, dads and sons aren't real code.
Actually I was wrong to say Adding a ParentFieldLayoutKey resolves the issue, as the issue is resolved even with the below xaml. Its having multiple field layout that resolves it, (thought behind the scene I would presume it is initialising ParentFieldLayoutKey same as when I explicitly initialise it)
<DataPresenter:FieldLayout Key="DadModel"> <!-- DadModel can be two different classes DadModel or GroupModel --> ... <DataPresenter:Field Name="GroupComponentModels" /> <DataPresenter:Field Name="SonModels" /> </DataPresenter:FieldLayout> <DataPresenter:FieldLayout Key="GroupComponentModel"> ... <DataPresenter:Field Name="SonModels" /> </DataPresenter:FieldLayout> <DataPresenter:FieldLayout Key="SonModel" > ... </DataPresenter:FieldLayout> <DataPresenter:FieldLayout Key="SonModel" > ... </DataPresenter:FieldLayout
eg.
<DataPresenter:FieldLayout Key="SonModel" ParentFieldLayoutKey="DadModel"> {StaticResource SonModelFieldLayout } </DataPresenter:FieldLayout> <DataPresenter:FieldLayout Key="SonModel" ParentFieldLayoutKey="GroupComponentModel"> {StaticResource SonModelFieldLayout } </DataPresenter:FieldLayout>
As you may already know ParentFieldLayout is not a settable property. Do you have a screenshot of the desired behavior. Are you looking for grouped columns? Placing multiple FieldLayouts with a key of SonModel works? I'm not entirely sure but if Sons is inherited by Dad, it would also need to be inherited by ComponentDad. And you won't be able to have a flat list of Dads and ComponentDads on the same level. Typically a grid displays a collection of one single type. You can refer to this thread for more detailshttps://www.infragistics.com/community/forums/f/ultimate-ui-for-wpf/101984/how-to-display-columns-from-different-object-types-in-xamdatagrid