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 StandardDataBindingUserControl() { 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 #standardDataBinding // Set type of POCO-ViewModel mvvmContext.ViewModelType = typeof(ViewModel); ViewModel viewModel = mvvmContext.GetViewModel <ViewModel>(); // Data binding for the Title property (via the DataBindings collection) editor.DataBindings.Add("EditValue", viewModel, "Title", true, DataSourceUpdateMode.OnPropertyChanged); // UI binding for the Report command commandButton.Click += (s, e) => XtraMessageBox.Show(viewModel.GetTitleAsHumanReadableString()); #endregion #standardDataBinding }
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 static object GetViewModel(this Control @this, Type type) { if (@this != null) { MVVMContext context = MVVMContext.FromControl(@this); if (context != null && context.ViewModelType == type) { return(MVVMContext.GetViewModel(@this)); } var dockPanel = @this as DockPanel; if (dockPanel != null) { return(GetViewModel(dockPanel.DockManager.Form, type)); } if (@this.Parent != null) { return(GetViewModel(@this.Parent, type)); } } return(null); }
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(UCLogDetailViewModel); var viewModel = context.GetViewModel <UCLogDetailViewModel>(); this.tabLogDetailInfo.SelectedPageChanging += (sender, e) => { if (e.Page == this.tabDrawInfos && (!viewModel.DrawLogEnabled)) { e.Cancel = true; } }; viewModel.Register("AddSysLog", x => { this.tabLogDetailInfo.BeginInvoke(new Action(() => { this.tabLogDetailInfo.SelectedTabPageIndex = 1; })); this.AddSystemInfos(x); }); }
public void SetGridName(string gridName) { mvvmContextQueryGridControl.GetViewModel <QueryGridControlViewModel>().GridName = gridName; }
private void OnDisposing() { var viewModel = MVVMContext.GetViewModel <MachineCountViewModel>(this); viewModel?.Dispose(); }
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(); }; }
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); }; }