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
One FieldLayout for multiple XamDataGrids


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:


Based On="FieldLayout1"


  • 18204
    Verified Answer
    Offline posted

    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:FieldLayout local:MainWindow.FromResource="{StaticResource layout}">

    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.