internal void LoadNewList(List <LanguageInfo> languageList)
        {
            if (languageList.Count >= 1)
            {
                foreach (LanguageInfo remoteLang in languageList)
                {
                    int oldIndex = LanguageList.IndexOf(remoteLang);
                    if (oldIndex >= 0)
                    {
                        remoteLang.IsLocal   = LanguageList.ElementAt(oldIndex).IsLocal;
                        remoteLang.ItemState = LanguageList.ElementAt(oldIndex).ItemState;
                    }
                }

                LanguageList.Clear();
                LanguageList.Add(defaultLanguageInfo());

                foreach (LanguageInfo remoteLang in languageList)
                {
                    LanguageList.Add(remoteLang);
                }

                Save(true);
            }

            LanguageList.First().SetCurrentInternal(true);
        }
Ejemplo n.º 2
0
        private void GenerateMultilingualDataGridColumns()
        {
            // if it's the first load in an update, gets the specifications from the current model
            if (firstUpdateLoad)
            {
                SpecificationEnumList = new ObservableCollection <SpecificationEnum>(SpecModel.Enumerations);
            }
            // else, creates a new list
            else
            {
                SpecificationEnumList = new ObservableCollection <SpecificationEnum>();
            }

            // Binds the datagrid to the list
            dgEnumeration.ItemsSource = SpecificationEnumList;
            dgEnumeration.DataContext = SpecificationEnumList;

            dgEnumeration.Columns.Clear();

            // For each language it will check whether the items exist to bind on, and it will create a binded column
            foreach (var lang in LanguageList)
            {
                // Checks if each enumeration has a value for the current language
                foreach (var en in SpecModel.Enumerations)
                {
                    // Checks if there is already a localized enumeration value in the list.
                    var locEnum = en.LocalizedEnumValues.FirstOrDefault(x => x.LanguageID == lang.ID);

                    // If there is not one yet (for example in a create form, or in an update when a language was added)
                    if (locEnum == null)
                    {
                        // Create a new localized enumeration value and adds it to the model
                        locEnum = new LocalizedEnumValue()
                        {
                            LanguageID    = lang.ID,
                            EnumerationID = en.ID
                        };
                        en.LocalizedEnumValues.Add(locEnum);
                    }
                }

                // Creates a new textblock which will be used as header for the column
                TextBlock header = new TextBlock
                {
                    Text = lang.LocalName
                };
                header.Typography.Capitals = FontCapitals.SmallCaps;


                // Creates a constant binding location
                int     index           = LanguageList.IndexOf(lang);
                string  Bindinglocation = $"LocalizedEnumValues[{index}].Value";
                Binding valuesBinding   = new Binding(Bindinglocation);

                // Adds a column and adds a binding based on the matching language
                DataGridTextColumn dgCol
                    = new DataGridTextColumn
                    {
                    Header  = header,
                    Binding = valuesBinding,
                    Width   = new DataGridLength(1.0, DataGridLengthUnitType.Star)
                    };
                dgEnumeration.Columns.Add(dgCol);
            }

            if (!firstUpdateLoad)
            {
                // Add an empty row per default
                AddEnumRow(null, null);
            }
        }