Пример #1
0
        public static void LocalizeDropdown(ComboBox ddl)
        {
            var eventHandlers = ddl.RemoveEventHandlers(nameof(ddl.SelectionChanged));

            var items        = ddl.Items.Cast <DdlItem>().ToArray();
            var selectedItem = ddl.SelectedItem();

            ddl.ItemsSource = null;
            var itemTexts = LocalizedStrings.Single(ls => ls.Key.AfterFirst("_") == "ComboBox_Items_" + ddl.Name).Value.Split(",", false, StringSplitOptions.None);

            for (var i = 0; i < items.Length; i++)
            {
                if (!String.IsNullOrEmpty(itemTexts[i]))
                {
                    items[i].Text = itemTexts[i];
                }
            }
            ddl.ItemsSource = items;
            ddl.SelectByItem(selectedItem);

            ddl.AddEventHandlers(nameof(ddl.SelectionChanged), eventHandlers);
        }