public InterationViewModel() { //创建一个交互请求,这个交互请求的作用就是向控制层(InteractionExample)发送一个打开对话窗的通知 this.alertDialogRequest = new InteractionRequest <DialogNotification>(this); this.toastRequest = new InteractionRequest <ToastNotification>(this); this.loadingRequest = new InteractionRequest <VisibilityNotification>(); //创建一个打响应按钮事件的命令 this.openAlertDialog = new SimpleCommand(() => { //设置命令的Enable为false,通过数据绑定解耦,间接将视图层按钮设置为不可点击状态 this.openAlertDialog.Enabled = false; //创建一个对话框通知 DialogNotification notification = new DialogNotification("Interation Example", "This is a dialog test.", "Yes", "No", true); //创建一个回调函数,此回调函数会在AlertDialog对话框关闭时调用 Action <DialogNotification> callback = n => { //设置命令的Enable为true,通过绑定会自动恢复按钮的点击状态 this.openAlertDialog.Enabled = true; if (n.DialogResult == AlertDialog.BUTTON_POSITIVE) { Debug.LogFormat("Click: Yes"); } else if (n.DialogResult == AlertDialog.BUTTON_NEGATIVE) { Debug.LogFormat("Click: No"); } }; //交互请求向View层OnOpenAlert函数发送通知 this.alertDialogRequest.Raise(notification, callback); }); this.showToast = new SimpleCommand(() => { ToastNotification notification = new ToastNotification("This is a toast test.", 2f); this.toastRequest.Raise(notification); }); this.showLoading = new SimpleCommand(() => { VisibilityNotification notification = new VisibilityNotification(true); this.loadingRequest.Raise(notification); }); this.hideLoading = new SimpleCommand(() => { VisibilityNotification notification = new VisibilityNotification(false); this.loadingRequest.Raise(notification); }); }
public InterationViewModel() { this.alertDialogRequest = new InteractionRequest <DialogNotification>(this); this.toastRequest = new InteractionRequest <Notification>(this); this.loadingRequest = new InteractionRequest <VisibilityNotification>(); this.openAlertDialog = new SimpleCommand(() => { this.openAlertDialog.Enabled = false; DialogNotification notification = new DialogNotification("Interation Example", "This is a dialog test.", "Yes", "No", true); Action <DialogNotification> callback = n => { this.openAlertDialog.Enabled = true; if (n.DialogResult == AlertDialog.BUTTON_POSITIVE) { Debug.LogFormat("Click: Yes"); } else if (n.DialogResult == AlertDialog.BUTTON_NEGATIVE) { Debug.LogFormat("Click: No"); } }; this.alertDialogRequest.Raise(notification, callback); }); this.showToast = new SimpleCommand(() => { Notification notification = new Notification("This is a toast test."); this.toastRequest.Raise(notification); }); this.showLoading = new SimpleCommand(() => { VisibilityNotification notification = new VisibilityNotification(true); this.loadingRequest.Raise(notification); }); this.hideLoading = new SimpleCommand(() => { VisibilityNotification notification = new VisibilityNotification(false); this.loadingRequest.Raise(notification); }); }
private void OnOpenAlert(object sender, InteractionEventArgs args) { DialogNotification notification = args.Context as DialogNotification; var callback = args.Callback; if (notification == null) { return; } AlertDialog.ShowMessage(notification.Message, notification.Title, notification.ConfirmButtonText, null, notification.CancelButtonText, notification.CanceledOnTouchOutside, (result) => { notification.DialogResult = result; if (callback != null) { callback(); } }); }
private void ValidatePhoneNumber() { if (string.IsNullOrEmpty(this.phoneNumber) || !Regex.IsMatch(this.phoneNumber, @"^1([38]\d|5[0-35-9]|7[3678])\d{8}$")) { //DialogNotification notification = new DialogNotification("", $"当前输入号码有误,请正确输入", "确定", true); //System.Action<DialogNotification> callback = n => //{ // if (n.DialogResult == AlertDialog.BUTTON_POSITIVE) // { // this.receiveReward.Enabled = true; // } //}; //this.alertDialogRequest.Raise(notification, callback); ToastNotification notification = new ToastNotification("当前输入号码有误,请正确输入", 2f); this.toastRequest.Raise(notification); this.receiveReward.Enabled = true; } else { DialogNotification notification = new DialogNotification("请确认你的手机号", $"{this.phoneNumber}", "领取奖券", "重新输入", true); System.Action <DialogNotification> callback = n => { if (n.DialogResult == AlertDialog.BUTTON_POSITIVE) { //ClosePage(); this.receiveReward.Enabled = false; } else if (n.DialogResult == AlertDialog.BUTTON_NEGATIVE) { this.receiveReward.Enabled = true; } }; this.alertDialogRequest.Raise(notification, callback); } }
public RewardViewModel(List <Reward> rewards) : base() { ApplicationContext context = Context.GetApplicationContext(); ITask task = context.GetService <ITask>(); //CouponViewModel couponViewModel = new CouponViewModel((model) => { // Icon = model.Icon; //}); //couponViewModel.Icon = "a4"; //couponViewModel.Name = "肯德基"; //couponViewModel.Desc = "肯德基4折优惠券"; //coupons.Add(couponViewModel); //CouponViewModel couponViewModel1 = new CouponViewModel((model)=> { // Icon = model.Icon; //}); //couponViewModel1.Icon = "a9"; //couponViewModel1.Name = "肯德基1"; //couponViewModel1.Desc = "肯德基4折优惠券"; //coupons.Add(couponViewModel1); foreach (Reward reward in rewards) { CouponViewModel couponViewModel = new CouponViewModel((model) => { Icon = model.Icon; }); couponViewModel.Icon = reward.DescIcon; couponViewModel.Name = reward.Name; couponViewModel.Desc = reward.Desc; coupons.Add(couponViewModel); } Icon = rewards[0].DescIcon; this.alertDialogRequest = new InteractionRequest <DialogNotification>(this); this.interactionFinished = new InteractionRequest(this); this.toastRequest = new InteractionRequest <ToastNotification>(this); this.receiveReward = new SimpleCommand(() => { this.receiveReward.Enabled = false; ValidatePhoneNumber(); }); this.terminate = new SimpleCommand(() => { this.receiveReward.Enabled = false; DialogNotification notification = new DialogNotification("", "你有奖券未领取,现在关闭奖券奖消失,是否强制关闭?", "继续关闭", "去领奖券", true); System.Action <DialogNotification> callback = n => { this.receiveReward.Enabled = true; if (n.DialogResult == AlertDialog.BUTTON_POSITIVE) { ClosePage(); } else if (n.DialogResult == AlertDialog.BUTTON_NEGATIVE) { } }; this.alertDialogRequest.Raise(notification, callback); }); this.result = task.Scheduled.ScheduleAtFixedRate(() => { CountDown -= 1; if (countDown <= 0) { ClosePage(); } }, 1000, 1000); }