public DataBindingViaMVVMContextFluentAPIUserControl()
        {
            InitializeComponent();
            #region SetUp
            MVVMContext mvvmContext = new MVVMContext();
            mvvmContext.ContainerControl = this;

            TextEdit editor = new TextEdit();
            editor.Dock = DockStyle.Top;
            editor.Properties.NullValuePrompt = "Please, enter the Title here...";
            editor.Properties.NullValuePromptShowForEmptyValue = true;

            SimpleButton commandButton = new SimpleButton();
            commandButton.Dock = DockStyle.Top;
            commandButton.Text = "Report the Title property value";

            commandButton.Parent = this;
            editor.Parent        = this;
            #endregion SetUp

            #region #dataBindingViaMVVMContextFluentAPI
            var legacyViewModel = new LegacyViewModel("Legacy ViewModel");
            // initialize the MVVMContext with the specific ViewModel's instance
            mvvmContext.SetViewModel(typeof(LegacyViewModel), legacyViewModel);
            // Data binding for the Title property (via MVVMContext API)
            var fluentAPI = mvvmContext.OfType <LegacyViewModel>();
            fluentAPI.SetBinding(editor, e => e.EditValue, x => x.Title);
            // UI binding for the Report command
            commandButton.Click += (s, e) => XtraMessageBox.Show(legacyViewModel.Title);
            #endregion #dataBindingViaMVVMContextFluentAPI
        }
Exemplo n.º 2
0
        public void SetDataContext(FrmCircleViewModel viewModel)
        {
            var context = new MVVMContext();

            context.ContainerControl = this;
            context.SetViewModel(typeof(FrmCircleViewModel), viewModel);

            var fluent = context.OfType <FrmCircleViewModel>();

            //this.ucInputCnt.Number = viewModel.Count;
            //this.ucInputCnt.NumberChanged += (sender, e) => viewModel.Count = (int)this.ucInputCnt.Number;
            //fluent.SetTrigger(x => x.Count, cnt => this.ucInputCnt.Number = cnt);

            fluent.SetBinding(this.ucInputCnt, e => e.Number, x => x.Count);

            this.ucInputInterval.Number         = viewModel.Interval;
            this.ucInputInterval.NumberChanged += (sender, e) => viewModel.Interval = (int)this.ucInputInterval.Number;
            fluent.SetTrigger(x => x.Interval, interval => this.ucInputInterval.Number = interval);

            this.radioGroupModel.SelectedIndex         = viewModel.Normal ? 0 : 1;
            this.radioGroupModel.SelectedIndexChanged += (sender, e) => viewModel.Normal = this.radioGroupModel.SelectedIndex == 0;
            fluent.SetTrigger(x => x.Normal, normal => this.radioGroupModel.SelectedIndex = normal ? 0 : 1);

            fluent.SetBinding(this.checkEditClear, e => e.Checked, x => x.ClearMachineCount);
            fluent.SetBinding(this.checkEditStart, e => e.Checked, x => x.MachineImmediately);

            this.btnAbort.Click  += (sender, e) => { viewModel.Result = DialogResult.Abort; this.Close(); };
            this.btnOK.Click     += (sender, e) => { this.btnOK.Focus(); viewModel.Result = DialogResult.OK; this.Close(); };
            this.btnCancel.Click += (sender, e) => { viewModel.Result = DialogResult.Cancel; this.Close(); };

            fluent.SetBinding(this.radioGroupModel, e => e.Enabled, x => x.Enabled);
            fluent.SetBinding(this.checkEditStart, e => e.Enabled, x => x.Enabled);
        }
Exemplo n.º 3
0
        protected MVVMContextFluentAPI <TModel> GetModelBindingManager(TModel model)
        {
            var mvvmContext = new MVVMContext();

            mvvmContext.ContainerControl = this;
            mvvmContext.SetViewModel(typeof(TModel), model);
            var fluentAPI = mvvmContext.OfType <TModel>();

            return(fluentAPI);
        }