public FluentAPIForCommandsUserControl() { InitializeComponent(); #region SetUp MVVMContext mvvmContext = new MVVMContext(); mvvmContext.ContainerControl = this; ProgressBarControl progressBar = new ProgressBarControl(); progressBar.Dock = DockStyle.Top; SimpleButton commandButton = new SimpleButton(); commandButton.Text = "Start Command Execution"; commandButton.Dock = DockStyle.Top; SimpleButton cancelButton = new SimpleButton(); cancelButton.Text = "Cancel Command Execution"; cancelButton.Dock = DockStyle.Top; cancelButton.Parent = this; commandButton.Parent = this; progressBar.Parent = this; #endregion SetUp #region #fluentAPIForCommands mvvmContext.ViewModelType = typeof(ViewModelWithAsyncCommandAndCancellation); var fluentAPI = mvvmContext.OfType <ViewModelWithAsyncCommandAndCancellation>(); // UI binding for button fluentAPI.BindCommand(commandButton, x => x.DoSomethingAsynchronously()); // UI binding for cancelation fluentAPI.BindCancelCommand(cancelButton, x => x.DoSomethingAsynchronously()); // UI binding for progress fluentAPI.SetBinding(progressBar, p => p.EditValue, x => x.Progress); #endregion #fluentAPIForCommands }
public SimpleUITriggerFluentAPIUserControl() { InitializeComponent(); #region SetUp MVVMContext mvvmContext = new MVVMContext(); mvvmContext.ContainerControl = this; CheckEdit checkEdit = new CheckEdit(); checkEdit.Dock = DockStyle.Top; checkEdit.Text = "IsActive"; LabelControl label = new LabelControl(); label.Dock = DockStyle.Top; label.AutoSizeMode = LabelAutoSizeMode.Vertical; label.Text = "Inactive"; label.Parent = this; checkEdit.Parent = this; #endregion SetUp #region #simpleUITriggerFluentAPI // Set type of POCO-ViewModel mvvmContext.ViewModelType = typeof(UIViewModel); // Data binding for the IsActive property var fluentAPI = mvvmContext.OfType <UIViewModel>(); fluentAPI.SetBinding(checkEdit, c => c.Checked, x => x.IsActive); // Property-change Trigger for the IsActive property fluentAPI.SetTrigger(x => x.IsActive, (active) => { label.Text = active ? "Active" : "Inactive"; }); #endregion #simpleUITriggerFluentAPI }
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 }
public SendingAndReceivingTokenizedMessagesUserControl() { InitializeComponent(); #region SetUp MVVMContext mvvmContext = new MVVMContext(); mvvmContext.ContainerControl = this; SimpleButton sendMessageButton = new SimpleButton(); sendMessageButton.Text = "Send Message"; sendMessageButton.Dock = DockStyle.Top; sendMessageButton.Parent = this; #endregion SetUp #region #sendingAndReceivingTokenizedMessages // add another view TokenizedMessagesAwareView msgView = new TokenizedMessagesAwareView(); msgView.Parent = sendMessageButton.Parent; msgView.BringToFront(); // start listening the ViewModel's custom messages in View msgView.RegisterAsCustomMessageRecepient(); mvvmContext.ViewModelType = typeof(ViewModelWithTokenizedMessages); // UI bindings for SendCustomMessage commands var fluentAPI = mvvmContext.OfType <ViewModelWithTokenizedMessages>(); fluentAPI.BindCommand(sendMessageButton, x => x.SendTokenizedMessage()); #endregion #sendingAndReceivingTokenizedMessages }
public DataBindingToNestedPropertiesFluentAPIUserControl() { 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 #dataBindingToNestedPropertiesFluentAPI // Set type of POCO-ViewModel mvvmContext.ViewModelType = typeof(ViewModel); // Data binding for the Title property of nested ViewModel (via MVVMContext FluentAPI) var fluent = mvvmContext.OfType <ViewModel>(); fluent.SetBinding(editor, e => e.EditValue, x => x.Child.Title); // UI binding for the Report command ViewModel viewModel = mvvmContext.GetViewModel <ViewModel>(); commandButton.Click += (s, e) => XtraMessageBox.Show(viewModel.GetChildTitleAsHumanReadableString()); #endregion #dataBindingToNestedPropertiesFluentAPI }
private void InitializeBindings() { var context = new MVVMContext(); context.ContainerControl = this; context.ViewModelType = typeof(UCStatusBarInfoViewModel); var fluent = context.OfType <UCStatusBarInfoViewModel>(); var viewModel = context.GetViewModel <UCStatusBarInfoViewModel>(); fluent.WithEvent <ItemClickEventArgs>(this.barManager1, "ItemClick") .EventToCommand(x => x.MakeOperation(0), args => this.HandlePopupClickInfo(args)); #region Property fluent.SetBinding(this.labelCanvasPos, e => e.Text, x => x.CanvasPos, canvasPos => $"{canvasPos.X.ToString("0.00")}, {canvasPos.Y.ToString("0.00")}"); fluent.SetBinding(this.dropBtnCoordinate, e => e.Text, x => x.CurrentPos, currentPos => $"(X:{currentPos.X.ToString("0.00")}, Y:{currentPos.Y.ToString("0.00")})"); fluent.SetBinding(this.checkBtnFine, e => e.Checked, x => x.FineEnabled); fluent.SetBinding(this.labelOperation, e => e.Text, x => x.Operation); fluent.SetBinding(this.barButtonItem3, e => e.Enabled, x => x.OperEnabled); fluent.SetBinding(this.barButtonItem4, e => e.Enabled, x => x.OperEnabled); fluent.SetBinding(this.barButtonItem5, e => e.Enabled, x => x.OperEnabled); this.ucInputDis.DataBindings.Add("Enabled", this.checkBtnFine, "Checked"); this.ucInputDis.Number = viewModel.Distance; this.ucInputDis.NumberChanged += (sender, e) => viewModel.Distance = this.ucInputDis.Number; fluent.SetTrigger(x => x.Distance, distance => this.ucInputDis.Number = distance); #endregion }
public PassingParametersToCommandsUserControl() { InitializeComponent(); #region SetUp MVVMContext mvvmContext = new MVVMContext(); mvvmContext.ContainerControl = this; PanelControl panel = new PanelControl(); panel.Dock = DockStyle.Top; panel.Parent = this; LabelControl label = new LabelControl(); label.Text = "Click to Execute Command"; label.Dock = DockStyle.Fill; label.AutoSizeMode = LabelAutoSizeMode.None; label.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; label.Appearance.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center; label.Parent = panel; #endregion SetUp #region #passingParametersToCommands mvvmContext.ViewModelType = typeof(MouseDownAwareViewModel); // UI binding for the EventToCommand behavior mvvmContext.OfType <MouseDownAwareViewModel>() .WithEvent <MouseEventArgs>(label, "MouseDown") .EventToCommand(x => x.Report((string)null), x => x.Message); #endregion #passingParametersToCommands }
public DataBindingViaDefaultConvertersFluentAPIUserControl() { InitializeComponent(); #region SetUp MVVMContext mvvmContext = new MVVMContext(); mvvmContext.ContainerControl = this; TrackBarControl trackBar = new TrackBarControl(); trackBar.Dock = DockStyle.Top; trackBar.Properties.Minimum = 0; trackBar.Properties.Maximum = 100; TextEdit editor = new TextEdit(); editor.Dock = DockStyle.Top; editor.Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.Numeric; editor.Properties.Mask.EditMask = "P0"; editor.Properties.Mask.UseMaskAsDisplayFormat = true; editor.Parent = this; trackBar.Parent = this; #endregion SetUp #region #dataBindingViaDefaultConvertersFluentAPI // Set type of POCO-ViewModel mvvmContext.ViewModelType = typeof(ViewModel); // Data binding for the Progress property (via MVVMContext FluentAPI) var fluent = mvvmContext.OfType <ViewModel>(); fluent.SetBinding(trackBar, e => e.EditValue, x => x.Progress); fluent.SetBinding(editor, e => e.EditValue, x => x.Progress); #endregion #dataBindingViaDefaultConvertersFluentAPI }
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); }
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); }
private void InitializeBindings() { var fluent = mvvmContextQueryGridControl.OfType <QueryGridControlViewModel>(); fluent.SetBinding(this, x => x.DataSource, y => y.GridSource); fluent.SetTrigger(r => r.AddIndicator, showIndicator => { if (showIndicator) { ((QueryGridView)this.DefaultView).AddRowNumberColumn(); } }); }
private void InitializeBindings() { var context = new MVVMContext(); context.ContainerControl = this; context.ViewModelType = typeof(MachineViewModel); var viewModel = context.GetViewModel <MachineViewModel>(); var fluent = context.OfType <MachineViewModel>(); #region Command Bindings fluent.BindCommand(this.btnStart, (x, para) => x.RunOperation(para), x => "Start"); fluent.BindCommand(this.btnPause, x => x.Pause()); fluent.BindCommand(this.btnStop, x => x.StopOperation()); fluent.BindCommand(this.btnOutline, (x, para) => x.RunOperation(para), x => "Outline"); fluent.BindCommand(this.btnSimulate, (x, para) => x.RunOperation(para), x => "Simulate"); fluent.BindCommand(this.btnFastStart, (x, para) => x.RunOperation(para), x => "Fast"); fluent.BindCommand(this.btnEmpty, (x, para) => x.RunOperation(para), x => "Empty"); fluent.BindCommand(this.btnCircle, x => x.ConfigCirclePara()); fluent.BindCommand(this.btnLocate, x => x.LoacateBreakPoint()); fluent.BindCommand(this.btnBreakPointStart, (x, para) => x.RunOperation(para), x => "BreakPointStart"); fluent.BindCommand(this.btnForward, (x, para) => x.RunOperation(para), x => "Forward"); fluent.BindCommand(this.btnBackward, (x, para) => x.RunOperation(para), x => "Backward"); fluent.BindCommand(this.btnZero, x => x.MoveToZero()); #endregion #region Property Bindings fluent.SetBinding(this.checkReturn, e => e.Checked, x => x.IsReturnAfterMachine); fluent.SetBinding(this.cmbReturnPoint, e => e.SelectedIndex, x => x.ReturnPointIndex); fluent.SetBinding(this.checkReturnAfterStop, e => e.Checked, x => x.IsReturnZeroWhenStop); fluent.SetBinding(this.checkSelected, e => e.Checked, x => x.IsOnlyMachineSelected); fluent.SetBinding(this.checkSoftLimit, e => e.Checked, x => x.SoftwareLimitEnalbed); fluent.SetBinding(this.checkEdgeDetection, e => e.Checked, x => x.EdgeDetectoinEnabled); fluent.SetBinding(this.ucInputStep, e => e.Number, x => x.Step, m => double.Parse(SpeedUnitConverter.Convert(m)), r => SpeedUnitConverter.ConvertBack(r.ToString())); fluent.SetBinding(this.ucInputSpeed, e => e.Number, x => x.StepSpeed, m => double.Parse(SpeedUnitConverter.Convert(m)), r => SpeedUnitConverter.ConvertBack(r.ToString())); //this.ucInputStep.Number = viewModel.Step; //this.ucInputStep.NumberChanged += (sender, e) => viewModel.Step = this.ucInputStep.Number; //fluent.SetTrigger(x => x.Step, step => this.ucInputStep.Number = step); //this.ucInputSpeed.Number = viewModel.StepSpeed; //this.ucInputSpeed.NumberChanged += (sender, e) => viewModel.StepSpeed = this.ucInputSpeed.Number; //fluent.SetTrigger(x => x.StepSpeed, speed => this.ucInputSpeed.Number = speed); #endregion this.cmbReturnPoint.DataBindings.Add("Enabled", this.checkReturn, "Checked"); viewModel.StatusChanged += ViewModel_StatusChanged; viewModel.DisableLocateStatus += ViewModel_DisableLocateStatus; viewModel.Register("UpdateCirclePara", this.UpdateCircleConfig); }
public TestMainView() { Context = new MVVMContext(); Context.ViewModelType = typeof(MainViewModel); StartAction = new TestAction(); RestartAction = new TestAction(); TimerAction = new TestAction(); DisplayControl = new TestControl <string>(); OpacityControl = new TestControl <bool>(); var api = Context.OfType <MainViewModel>(); api.BindCommand(StartAction, vm => vm.Start()); api.BindCommand(RestartAction, vm => vm.Restart()); api.BindCommand(TimerAction, vm => vm.Tick()); api.SetBinding(DisplayControl, ctrl => ctrl.Value, vm => vm.DisplayText); api.SetBinding(OpacityControl, ctrl => ctrl.Value, vm => vm.IsTransparent); }
public FluentAPIForCommandsUserControl() { InitializeComponent(); #region SetUp MVVMContext mvvmContext = new MVVMContext(); mvvmContext.ContainerControl = this; SimpleButton commandButton = new SimpleButton(); commandButton.Text = "Execute Command"; commandButton.Dock = DockStyle.Top; commandButton.Parent = this; #endregion SetUp #region #fluentAPIForCommands mvvmContext.ViewModelType = typeof(ViewModelWithParametrizedConditionalCommand); // int parameter = 4; // UI binding for button with `queryParameter` function var fluentAPI = mvvmContext.OfType <ViewModelWithParametrizedConditionalCommand>(); fluentAPI.BindCommand(commandButton, (x, p) => x.DoSomething(p), x => parameter); #endregion #fluentAPIForCommands }
private void InitializeBindings() { var context = new MVVMContext(); context.ContainerControl = this; context.ViewModelType = typeof(RibPageMachineViewModel); var fluent = context.OfType <RibPageMachineViewModel>(); var viewModel = context.GetViewModel <RibPageMachineViewModel>(); #region Register UI handler viewModel.Register("AttachToMenu", x => this.AttachToMenu()); viewModel.Register("RemoveFromMenu", x => this.RemoveFromMenu()); viewModel.Register("UpdateOperation", x => this.UpdateStatus((string)x)); #endregion #region Property fluent.SetBinding(this.txtTime, e => e.Text, x => x.MachineTime, m => m.ToString(@"hh\:mm\:ss\.fff")); fluent.SetBinding(this.progressBarMachine, e => e.EditValue, x => x.Progress); fluent.SetBinding(this.txtSpeedX, e => e.Text, x => x.XSpeed, m => m.ToString("0.00") + "mm/s"); fluent.SetBinding(this.txtSpeedY, e => e.Text, x => x.YSpeed, m => m.ToString("0.00") + "mm/s"); fluent.SetBinding(this.txtSpeed, e => e.Text, x => x.Speed, m => m.ToString("0.00") + "mm/s"); fluent.SetBinding(this.txtPosX, e => e.Text, x => x.XPos, m => m.ToString("0.00") + "mm"); fluent.SetBinding(this.txtPosY, e => e.Text, x => x.YPos, m => m.ToString("0.00") + "mm"); fluent.SetBinding(this.txtFollow, e => e.Text, x => x.FollowHeight, m => m.ToString("0.00") + "mm"); fluent.SetBinding(this.txtActualFollow, e => e.Text, x => x.ActualFollowHeight, m => m.ToString("0.00") + "mm"); fluent.SetBinding(this.txtPosZ, e => e.Text, x => x.ZPos, m => m.ToString("0.00") + "mm"); fluent.SetBinding(this.txtFrequency, e => e.Text, x => x.Frequency, m => m.ToString("0.00") + "Hz"); fluent.SetBinding(this.txtPower, e => e.Text, x => x.Power, m => m.ToString("0.00") + "%"); fluent.SetBinding(this.txtDuty, e => e.Text, x => x.DutyCircle, m => m.ToString("0.00") + "%"); #endregion #region Command fluent.BindCommand(this.btnStart, x => x.Resume()); fluent.BindCommand(this.btnPause, x => x.Pause()); fluent.BindCommand(this.btnStop, x => x.Stop()); #endregion }
private void InitializeBindings() { var context = new MVVMContext(); context.ContainerControl = this; context.ViewModelType = typeof(CanvasViewModel); var fluent = context.OfType <CanvasViewModel>(); this.viewModel = context.GetViewModel <CanvasViewModel>(); this.viewModel.InjectHandler(needToSort => { if (needToSort) { this.OnSortDrawObjects?.Invoke(this, EventArgs.Empty); } var tmp = this.drawingComponent1.GetDrawObjects(); var part1 = tmp.Where(x => ((DrawObjectBase)x).LayerId == 15).ToList(); var part2 = tmp.Where(x => ((DrawObjectBase)x).LayerId < 15 || ((DrawObjectBase)x).LayerId == 17).ToList(); var part3 = tmp.Where(x => ((DrawObjectBase)x).LayerId == 16).ToList(); if (part1.Any() || part3.Any()) { tmp.Clear(); tmp.AddRange(part1); tmp.AddRange(part2); tmp.AddRange(part3); for (int i = 0; i < tmp.Count; i++) { tmp[i].GroupParam.FigureSN = (i + 1); } } return(tmp); }); this.viewModel.InjectPaserFunc(x => { var items = FigureHelper.ToFigureBaseModel(x); items.ForEach(m => m.IsSelected = false); return(JsonConvert.SerializeObject(items)); }); this.viewModel.Register("MarkClear", this.ClearMark); this.viewModel.Register("MarkPointChanged", this.UpdateMarkPoint); this.viewModel.Register("MarkPathAdd", this.AddMarkPathPoint); this.viewModel.Register("AutoRefresh", this.OnAutoRefreshChanged); this.viewModel.Register("MarkFlagChanged", this.UpdateMarkFlag); this.viewModel.Register("RelativePosChanged", this.UpdateRelativePos); this.viewModel.Register("FiguresMove", this.MoveAll); this.viewModel.Register("SetCanvasView", this.SetCanvasView); this.viewModel.Register("CanvasStatusChanged", this.OnStatusChanged); this.viewModel.Register("UpdateOutline", this.UpdateOutline); this.viewModel.InitCanvas(); this.drawingComponent1.OnPositionChanged += (sender, e) => { PointF point = new PointF { X = (float)e.CurrentPoint.X, Y = (float)e.CurrentPoint.Y }; this.viewModel.UpdateCanvasPos(point); }; }
private void InitializeBindings() { var context = new MVVMContext(); context.ContainerControl = this; context.ViewModelType = typeof(MachineCountViewModel); var fluent = context.OfType <MachineCountViewModel>(); var viewModel = context.GetViewModel <MachineCountViewModel>(); fluent.SetBinding(this.lblFinishCount, e => e.Text, x => x.CurrentCount); fluent.SetBinding(this.lblPlanTotalCount, e => e.Text, x => x.TotalCount); fluent.SetBinding(this.lblCurTime, e => e.Text, x => x.RunningPeroid, period => { string timeStr = null; if (period.Days != 0) { timeStr += period.Days + "天"; } if (period.Hours != 0) { timeStr += period.Hours + "小时"; } if (period.Minutes != 0) { timeStr += period.Minutes + "分"; } if (period.Seconds != 0) { timeStr += period.Seconds + "秒"; } return(timeStr); }); fluent.SetBinding(this.lblTotalTime, e => e.Text, x => x.CountdownPeriod, period => { string timeStr = null; if (period == null) { this.lblTotalTime.Visible = false; } else { this.lblTotalTime.Visible = true; timeStr = "-" + period.Value.ToString(@"hh\:mm\:ss"); } return(timeStr); }); fluent.BindCommand(this.btnManager, x => x.ConfigParameter()); viewModel.Register("ConfigPara", x => { FrmMachineCount frm = new FrmMachineCount(GlobalModel.Params.MachineCount); if (frm.ShowDialog() == DialogResult.OK) { GlobalModel.Params.MachineCount = frm.Model; } }); this.Load += (sender, e) => { GlobalModel.Params.MachineCount.IsAutoSuspend = false; viewModel.UpdatePara(); }; }
public DataBindingWithCustomConvertersFluentAPIUserControl() { InitializeComponent(); #region SetUp MVVMContext mvvmContext = new MVVMContext(); mvvmContext.ContainerControl = this; CheckEdit check = new CheckEdit(); check.Dock = DockStyle.Top; check.Properties.AllowGrayed = true; SimpleButton commandButton = new SimpleButton(); commandButton.Dock = DockStyle.Top; commandButton.Text = "Report the ModelState property value"; check.Parent = this; commandButton.Parent = this; #endregion SetUp #region #dataBindingWithCustomConvertersFluentAPI // Set type of POCO-ViewModel mvvmContext.ViewModelType = typeof(ViewModel); // Data binding for the ModelState property (via MVVMContext FluentAPI) var fluent = mvvmContext.OfType <ViewModel>(); fluent.SetBinding(check, e => e.CheckState, x => x.ModelState, modelState => { // Convert the ViewModel.State to CheckState switch (modelState) { case ViewModel.State.Active: return(CheckState.Checked); case ViewModel.State.Inactive: return(CheckState.Unchecked); default: return(CheckState.Indeterminate); } }, checkState => { // Convert back from CheckState to the ViewModel.State switch (checkState) { case CheckState.Checked: return(ViewModel.State.Active); case CheckState.Unchecked: return(ViewModel.State.Inactive); default: return(ViewModel.State.Suspended); } }); fluent.SetBinding(check, e => e.Text, x => x.ModelState, modelState => string.Format("Click to change the current ViewModel state from {0} to {1}", modelState, (ViewModel.State)((1 + (int)modelState) % 3))); // UI binding for the Report command fluent.BindCommand(commandButton, x => x.ReportState()); #endregion #dataBindingWithCustomConvertersFluentAPI }