Hey,
I have a few UserControls with different hierarchical XamDataGrids, in which I display different DataViews tht still have the same FIeldLayouts.
I wanted to declare these FieldLayouts in the App.xaml Ressources and use these for all Grids. But I not get it done to acces these Layouts by their Key-Names. Is there a way like this:
<igDP:XamDataGrid Grid.Row="1" Name="XamDataGridProjects" Language="de-DE" > <igDP:XamDataGrid.FieldLayouts > <igDP:FieldLayout
Based On="FieldLayout1"
>
Hi Benedikt Luz,
Thank you for posting in our forums!
One issue with this is that the Fields cannot be "shared" across multiple grids at the same time, so if you have multiple grids displaying there would be some exceptions thrown in regards to the Fields.
The way to get around that issue is to write some logic that will copy the fields from your App.xaml FieldLayout and use them in the new instance. You can accomplish this with an attached property. Below is a brief code snippet.
public static readonly DependencyProperty FromResourceProperty = DependencyProperty.RegisterAttached("FromResource", typeof(FieldLayout), typeof(MainWindow), new PropertyMetadata((dp, args) => { FieldLayout newLayout = dp as FieldLayout; FieldLayout appLayout = args.NewValue as FieldLayout; // Copy the fields. foreach (Field fld in appLayout.Fields) { newLayout.Fields.Add(new Field() { Name = fld.Name }); } }));
Then you can use the attached property on your FieldLayouts:
<igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout local:MainWindow.FromResource="{StaticResource layout}"> </igDP:FieldLayout>
I have also attached my sample below that demonstrates this approach. If you have any further questions or concerns with this, please let me know.
5127.XamDataGrid_SharedFieldLayouts.zip