public ViewEditItem(DataStructure dataStructure, DataItem dataItem, string label, bool enableExport)
        {
            originalDataItem = dataItem;
            copiedDataItem   = ObjectCopier.Clone <DataItem>(dataItem);

            InitializeComponent();

            ItemName.Content        = label;
            ExportButton.Visibility = enableExport ? Visibility.Visible : Visibility.Collapsed;

            Dictionary <string, List <Field> > tabsDict = dataStructure.GetTabs(false);

            foreach (string tabName in tabsDict.Keys)
            {
                TabItem tabItem = new TabItem();
                tabItem.Header = tabName;
                tabs.Items.Add(tabItem);

                ScrollViewer scroll = new ScrollViewer();
                StackPanel   sp     = new StackPanel();
                scroll.Content = sp;
                sp.Orientation = System.Windows.Controls.Orientation.Vertical;
                foreach (Field tabField in tabsDict[tabName])
                {
                    FieldControl userControl = tabField is ExternalDataStructureList?originalDataItem.GetField(tabField.Id).GenerateUIElement(true) : copiedDataItem.GetField(tabField.Id).GenerateUIElement(true);

                    userControl.SetEditable(false);
                    allUserControls.Add(userControl);
                    sp.Children.Add(userControl);
                }

                tabItem.Content = scroll;
            }
        }
Ejemplo n.º 2
0
        public NewEntry(DataStructure dataStructure, Action <DataItem> onSave)
        {
            InitializeComponent();

            this.dataStructure = dataStructure;
            this.onSave        = onSave;

            dataItem = new DataItem(dataStructure);
            Dictionary <string, List <Field> > tabs = dataStructure.GetTabs(true);

            if (tabs.Keys.Count > 1)
            {
                foreach (string tabName in tabs.Keys)
                {
                    StackPanel newPanel = new StackPanel();
                    newPanel.Orientation = Orientation.Horizontal;
                    Label dummyLabel = new Label();
                    dummyLabel.Width = 50;
                    newPanel.Children.Add(dummyLabel);
                    StackPanel container = new StackPanel();
                    newPanel.Children.Add(container);
                    Expander expander = new Expander();
                    expander.IsExpanded = true;
                    expander.Header     = tabName;
                    expander.Content    = newPanel;
                    List <Field> fields = new List <Field>();
                    foreach (Field tabField in tabs[tabName])
                    {
                        fields.Add(dataItem.GetField(tabField.Id));
                    }
                    AddFields(container, fields);
                    MainContainer.Children.Add(expander);
                }
            }
            else if (tabs.Keys.Count == 1)
            {
                List <Field> fields = new List <Field>();
                foreach (Field tabField in tabs.Values.First())
                {
                    fields.Add(dataItem.GetField(tabField.Id));
                }
                AddFields(MainContainer, fields);
            }
        }