Example #1
0
        public CreateSchemaObjectDialog()
        {
            model       = new CSOViewModel();
            DataContext = model;

            Title     = "Create an Object by Schema";
            Padding   = 5;
            Resizable = true;

            types         = ListAvailableTypes();
            typesFiltered = types;

            search = new SearchBox
            {
                PlaceholderText = "Search for a schema class"
            };
            search.Focus();
            search.TextChanged += Search_TextChanged;


            //list = new ListBox
            //{
            //  Size = new Size(200, 200),
            //  ItemTextBinding = Binding.Property<Type, string>(x => x.Name),
            //  DataStore = typesFiltered,
            //  SelectedIndex = 0
            //};
            //list.SelectedIndexBinding.BindDataContext((CSOViewModel m) => m.SelectedIndex, DualBindingMode.OneWayToSource);
            //list.SelectedValueBinding.BindDataContext((CSOViewModel m) => m.SelectedType, DualBindingMode.OneWayToSource);


            tree = new TreeGridView {
                Size = new Size(300, 200)
            };
            tree.Columns.Add(new GridColumn {
                DataCell = new TextBoxCell(0)
            });
            tree.DataStore = GenerateTree();
            tree.BindDataContext(x => x.SelectedItem, (CSOViewModel m) => m.SelectedItem, DualBindingMode.OneWayToSource);

            description = new TextArea
            {
                ReadOnly = true,
                Size     = new Size(400, 200)
            };

            description.TextBinding.BindDataContext(Binding.Property((CSOViewModel m) => m.SelectedItem).
                                                    Convert(x => GetDescription(x)), DualBindingMode.OneWay);

            Content = new TableLayout
            {
                Spacing = new Size(5, 5),
                Padding = new Padding(10),
                Rows    =
                {
                    new TableRow(search),
                    new TableRow(tree,   description),
                }
            };

            // buttons
            DefaultButton = new Button {
                Text = "Create"
            };
            DefaultButton.BindDataContext(x => x.Enabled, Binding.Property((CSOViewModel m) => m.SelectedItem)
                                          .Convert(x => x != null && x.Tag != null), DualBindingMode.OneWay);

            DefaultButton.Click += (sender, e) =>
            {
                HasResult = true;
                Close();
            };
            PositiveButtons.Add(DefaultButton);

            AbortButton = new Button {
                Text = "C&ancel"
            };
            AbortButton.Click += (sender, e) => Close();
            NegativeButtons.Add(AbortButton);
        }