コード例 #1
0
        public static BaseForm CreateOKCancel(string text, BaseAcceptableViewModel viewModel, params FormBuilderItem[] items)
        {
            var form = new BaseForm();

            form.Text       = text;
            form.ClientSize = new Size(100, 80);

            var okCancel = new OKCancelButtons();

            okCancel.Bind(viewModel, form);

            form.AcceptButton = okCancel.OK;
            form.CancelButton = okCancel.Cancel;

            var lc = new LayoutControl();

            lc.Dock = DockStyle.Fill;
            lc.AllowCustomization = false;
            form.Controls.Add(lc);

            lc.BeginUpdate();
            try
            {
                int i = 0;
                foreach (var item in items)
                {
                    var editor = item.Control;
                    var label  = item.Label;

                    var editorItem = lc.Root.AddItem();
                    editorItem.Control = editor;
                    editorItem.Name    = "editorItem" + i++;
                    if (string.IsNullOrEmpty(label))
                    {
                        editorItem.TextVisible = false;
                    }
                    else
                    {
                        editorItem.Text         = label;
                        editorItem.TextLocation = Locations.Top;
                    }
                }

                var okCancelItem = lc.Root.AddItem();
                okCancelItem.Control     = okCancel;
                okCancelItem.Name        = "OKCancel";
                okCancelItem.TextVisible = false;
            }
            finally
            {
                lc.EndUpdate();
            }

            var size = lc.GetPreferredSize(Size.Empty);

            form.ClientSize  = lc.GetPreferredSize(size);
            form.MinimumSize = form.Size;
            return(form);
        }
コード例 #2
0
 public static ControlCommandBinder[] Bind(this OKCancelButtons button, BaseAcceptableViewModel acceptable, IConfirmCommand cancel = null)
 {
     return(new[]
     {
         Bind(button.GetOK(), acceptable.Accept),
         Bind(button.GetCancel(), acceptable.Cancel, cancel),
     });
 }
コード例 #3
0
        private BaseForm CreateForm(BaseAcceptableViewModel viewModel)
        {
            if (viewModel is IngredientEditorViewModel)
            {
                var ingredient = (IngredientEditorViewModel)viewModel;
                var txtName    = new TextEdit();
                txtName.BindText(ingredient, i => i.Name);
                return(FormBuilder.CreateSimpleOKCancel("Edit Ingredient", ingredient, txtName, "Name:"));
            }
            else if (viewModel is RecipeEditorViewModel)
            {
                var recipe = (RecipeEditorViewModel)viewModel;

                var txtName = new TextEdit();
                txtName.BindText(recipe, r => r.Name);

                var tbl = new TableLayoutPanel();
                tbl.ColumnCount = 4;
                tbl.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
                tbl.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
                tbl.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
                tbl.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
                tbl.RowCount = 1;
                tbl.RowStyles.Add(new RowStyle(SizeType.AutoSize));
                tbl.Height      = 28;
                tbl.MinimumSize = new Size(0, 28);

                var btnModify = new SimpleButton();
                btnModify.Margin = new Padding(3);
                btnModify.Text   = "Modify Recipe";
                btnModify.Size   = new Size(96, 22);
                btnModify.Bind(recipe.ModifyRecipeCommand);

                var btnReduce = new SimpleButton();
                btnReduce.Margin = new Padding(3);
                btnReduce.Text   = "Reduce";
                btnReduce.Size   = new Size(96, 22);
                btnReduce.Bind(recipe.ReduceRecipeCommand);

                tbl.SuspendLayout();
                tbl.Controls.Add(btnModify, 1, 0);
                tbl.Controls.Add(btnReduce, 2, 0);
                tbl.ResumeLayout();

                var ctrlAmount = new AmountControl(false);
                ctrlAmount.BindAmount(recipe, r => r.Amount);
                ctrlAmount.BindMeasurement(recipe, r => r.Measurement);

                var grid = new EditableListGridControl <IngredientReferenceViewModel>(recipe);
                return(FormBuilder.CreateOKCancel("Edit Recipe", recipe,
                                                  new FormBuilderItem(txtName, "Name:"),
                                                  new FormBuilderItem(grid, "Items:"),
                                                  new FormBuilderItem(tbl),
                                                  new FormBuilderItem(ctrlAmount, "Makes:")));
            }
            else if (viewModel is IngredientReferenceEditorViewModel)
            {
                var ingredient = (IngredientReferenceEditorViewModel)viewModel;

                var cboIngredients = new SearchLookUpEdit();
                cboIngredients.Properties.View.Columns.AddVisible("Display").SortOrder = ColumnSortOrder.Ascending;
                cboIngredients.Properties.View.OptionsView.ShowColumnHeaders           = false;
                cboIngredients.Properties.View.OptionsView.ShowIndicator = false;
                cboIngredients.Properties.DataSource       = ingredient.Ingredients;
                cboIngredients.Properties.ValueMember      = "Value";
                cboIngredients.Properties.DisplayMember    = "Display";
                cboIngredients.Properties.ShowAddNewButton = true;
                cboIngredients.AddNewValue += (o, e) =>
                {
                    // execute the add ingredient command
                    ingredient.SearchText = cboIngredients.GetFilterText();
                    ingredient.AddIngredientCommand.Execute(this);
                    e.Cancel = true;
                };

                var binding = cboIngredients.BindEditValue(ingredient, (i => i.IngredientID));
                binding.DataSourceNullValue = null;

                var ctrlAmount = new AmountControl();
                ctrlAmount.BindAmount(ingredient, r => r.Amount);
                ctrlAmount.BindMeasurement(ingredient, r => r.Measurement);

                return(FormBuilder.CreateOKCancel("Edit Recipe Ingredient", ingredient,
                                                  new FormBuilderItem(cboIngredients, "Ingredient:"),
                                                  new FormBuilderItem(ctrlAmount)));
            }
            else if (viewModel is ModifyRecipeViewModel)
            {
                return(new ModifyRecipeDialog((ModifyRecipeViewModel)viewModel));
            }
            else if (viewModel is ReduceRecipeViewModel)
            {
                return(new ReduceRecipeDialog((ReduceRecipeViewModel)viewModel));
            }

            return(null);
        }
コード例 #4
0
 public static BaseForm CreateSimpleOKCancel(string text, BaseAcceptableViewModel viewModel, Control editor, string label = null)
 {
     return(CreateOKCancel(text, viewModel, new FormBuilderItem(editor, label)));
 }
コード例 #5
0
        private static async void PopWhenCompleted(BaseAcceptableViewModel viewModel)
        {
            await viewModel.Completed;

            Debug.Assert(sViewModels.Pop() == viewModel);
        }
コード例 #6
0
 internal static void Push(BaseAcceptableViewModel viewModel)
 {
     sViewModels.Push(viewModel);
     FireStackChanged();
     PopWhenCompleted(viewModel);
 }