Ejemplo n.º 1
0
        public override ISpawnList SaveWindowControls(StackPanel control, string name, Type type, object[] attributes)
        {
            int controlIndex = 0;

            controlIndex++;
            SpawnListBox          lbxValue = (SpawnListBox)control.Children[controlIndex];
            SpawnListBoxViewModel mv       = (SpawnListBoxViewModel)lbxValue.DataContext;

            return(mv.GetList(type));
        }
Ejemplo n.º 2
0
        public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, ISpawnList member)
        {
            LoadLabelControl(control, name);

            Type elementType = ReflectionExt.GetBaseTypeArg(typeof(ISpawnList <>), type, 0);

            SpawnListBox lbxValue = new SpawnListBox();

            lbxValue.MaxHeight = 220;
            SpawnListBoxViewModel mv = new SpawnListBoxViewModel(new StringConv(elementType, ReflectionExt.GetPassableAttributes(1, attributes)));

            lbxValue.DataContext = mv;

            //add lambda expression for editing a single element
            mv.OnEditItem += (int index, object element, SpawnListBoxViewModel.EditElementOp op) =>
            {
                string       elementName = name + "[" + index + "]";
                DataEditForm frmData     = new DataEditForm();
                frmData.Title = DataEditor.GetWindowTitle(parent, elementName, element, elementType, ReflectionExt.GetPassableAttributes(2, attributes));

                DataEditor.LoadClassControls(frmData.ControlPanel, parent, elementName, elementType, ReflectionExt.GetPassableAttributes(2, attributes), element, true);

                frmData.SelectedOKEvent += () =>
                {
                    element = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, elementType, ReflectionExt.GetPassableAttributes(2, attributes), true);
                    op(index, element);
                    frmData.Close();
                };
                frmData.SelectedCancelEvent += () =>
                {
                    frmData.Close();
                };

                control.GetOwningForm().RegisterChild(frmData);
                frmData.Show();
            };

            mv.LoadFromList(member);
            control.Children.Add(lbxValue);
        }