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
1865
Save Layout
posted

I have a tab-control and xamDataGrids on various tabs.

In my app, I want to implement the ability to save and load multiple layouts for each tab/xamDataGrid. Currently, I am using SaveCustomizations and LoadCustomizations to save layout. 

I there are sample app that shows how to implement this feature across the entire app where users can save and load multiple layouts for each tabs/xamDataGrids in the app.

Thanks.

  • 16495
    Offline posted

    Hello,

    I have created a simple project in order to show you how to save and load the layout of each XamDataGrid in your tabs. I have used XamTabControl's SelectionChanged event and it's AddedItems and  RemovedItems  collection to access the current grid and the next one, this way when the tab was changed the layout for the grid from current tab will be saved, then the layout for the grid in next tad will be loaded, for example:

    private void xamTabControl1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (e.RemovedItems.Count != 0 && e.AddedItems.Count != 0)
        {
            XamDataGrid oldGrid = (e.RemovedItems[0] as TabItemEx).Content as XamDataGrid;
            XamDataGrid newGrid = (e.AddedItems[0] as TabItemEx).Content as XamDataGrid;

            if (newGrid != null && newGrid.Tag != null)
            {
                newGrid.Loaded += (ss, ee) =>
                {
                    using (FileStream fs = new FileStream("xamDataGridLayout" + newGrid.Name.ToString() + ".xml", FileMode.Open, FileAccess.Read))
                    {
                       newGrid.LoadCustomizations(fs);
                    }
                };
            }
            using (FileStream fs = new FileStream("xamDataGridLayout" + oldGrid.Name.ToString() + ".xml", FileMode.Create, FileAccess.Write))
            {
                oldGrid.SaveCustomizations(fs);
                oldGrid.Tag = "available";
            }
        }
    }

    Let me know if you have any questions.

    Sincerely,
    Zhivko
    Associate Software Developer

    SaveMultipleLayouts.zip