示例#1
0
        public UIElement BuildDictionaryForm <Y, T>(FieldInfo pi, Dictionary <Y, T> dictionary)
        {
            var natt = pi.GetCustomAttribute <NecrobotConfigAttribute>();

            string resKey = $"Setting.{pi.Name}";

            ObservablePairCollection <Y, T> dataSource = new ObservablePairCollection <Y, T>(dictionary);

            map.Add(pi, dataSource);

            DataGrid grid = new DataGrid()
            {
                IsReadOnly          = false,
                AutoGenerateColumns = false
            };

            grid.ItemsSource = dataSource;

            var col1 = new DataGridComboBoxColumn()
            {
                Header = translator.PokemonName
            };

            col1.ItemsSource = Enum.GetValues(typeof(Y)).Cast <Y>();

            col1.SelectedItemBinding = new Binding("Key")
            {
                Mode = BindingMode.TwoWay
            };
            grid.Columns.Add(col1);
            var type = typeof(T);

            foreach (var item in type.GetProperties())
            {
                var att = item.GetCustomAttribute <NecrobotConfigAttribute>(true);
                if (att != null && !att.IsPrimaryKey)
                {
                    string headerKey       = $"{resKey}.{item.Name}";
                    var    dataGridControl = GetDataGridInputControl(item);
                    dataGridControl.Header = translator.GetTranslation(headerKey);

                    grid.Columns.Add(dataGridControl);
                }
            }
            return(grid);
        }
示例#2
0
        public UIElement BuildDictionaryForm <T>(FieldInfo pi, Dictionary <PokemonId, T> dictionary)
        {
            ObservablePairCollection <PokemonId, T> dataSource = new ObservablePairCollection <PokemonId, T>(dictionary);

            map.Add(pi, dataSource);

            DataGrid grid = new DataGrid()
            {
                IsReadOnly          = false,
                AutoGenerateColumns = false
            };

            grid.ItemsSource = dataSource;

            var col1 = new DataGridComboBoxColumn()
            {
                Header = "Pokemon Name"
            };

            col1.ItemsSource = Enum.GetValues(typeof(PokemonId)).Cast <PokemonId>();

            col1.SelectedItemBinding = new Binding("Key")
            {
                Mode = BindingMode.TwoWay
            };
            grid.Columns.Add(col1);
            var type = typeof(T);

            foreach (var item in type.GetProperties())
            {
                var att = item.GetCustomAttribute <ExcelConfigAttribute>(true);
                if (att != null && !att.IsPrimaryKey)
                {
                    var dataGridControl = GetDataGridInputControl(item);
                    grid.Columns.Add(dataGridControl);
                }
            }
            return(grid);
        }