当前位置: 首页 > news >正文

这几年做哪个网站致富百度指数分析平台

这几年做哪个网站致富,百度指数分析平台,外贸是做什么的很赚钱吗,小红书怎么推广自己的产品文章目录 使用ValidationRule实现检测用户输入EmptyValidationRule 非空校验TextBox设置非空校验TextBox设置非空校验并显示校验提示 结语 使用ValidationRule实现检测用户输入 EmptyValidationRule是TextBox内容是否为空校验,TextBox的Binding属性设置ValidationRu…

文章目录

  • 使用ValidationRule实现检测用户输入
    • EmptyValidationRule 非空校验
    • TextBox设置非空校验
    • TextBox设置非空校验并显示校验提示
  • 结语

使用ValidationRule实现检测用户输入

EmptyValidationRule是TextBox内容是否为空校验,TextBox的Binding属性设置ValidationRule后,TextBox将自带校验红框效果。但是默认是没有报错提示的。需要开启验证错误的通知属性 NotifyOnValidationError,这样可以通过绑定 Validation.Error 事件处理程序获取到Message进行提示

EmptyValidationRule 非空校验

public class EmptyValidationRule : ValidationRule
{public override ValidationResult Validate(object value, CultureInfo cultureInfo){string str = value as string;if (string.IsNullOrWhiteSpace(str)){return new ValidationResult(false, "不能为空,输入有效值");}return ValidationResult.ValidResult;}
}

TextBox设置非空校验

UpdateSourceTrigger="PropertyChanged" 设置每次输入都触发双向绑定,Binding.ValidationRules 设置校验逻辑
ValidatesOnTargetUpdated="True" 设置 首次加载就校验(默认启动程序的时候不开启校验,当你第一次输入才校验)

<StackPanelGrid.Row="1"HorizontalAlignment="Center"Orientation="Horizontal"><TextBlock VerticalAlignment="Center" Text="年龄:" /><TextBoxWidth="200"Height="30"Margin="10,0"VerticalAlignment="Center"VerticalContentAlignment="Center"><TextBox.Text><Binding Path="Age" UpdateSourceTrigger="PropertyChanged"><Binding.ValidationRules><Valid:EmptyValidationRule ValidatesOnTargetUpdated="True" /></Binding.ValidationRules></Binding></TextBox.Text></TextBox>
</StackPanel>

在这里插入图片描述
在这里插入图片描述

TextBox设置非空校验并显示校验提示

按照上述说明的【需要开启验证错误的通知属性 NotifyOnValidationError,这样可以通过绑定 Validation.Error 事件处理程序获取到Message进行提示】
这边采用的是WPF的行为Behavior。
IValidationExceptionHandler,输入校验接口,需要进行校验的页面的ViewModel需要继承并实现他的两个属性IsValid 以及
Message

/// <summary>
/// 输入校验接口
/// </summary>
public interface IValidationExceptionHandler
{/// <summary>/// 是否有校验异常/// </summary>bool IsValid { get; set; }/// <summary>/// 异常提示/// </summary>string Message { get; set; }
}
  1. 首先先定义一个行为 ValidationExceptionBehavior
public class ValidationExceptionBehavior : Behavior<FrameworkElement>
{// 实现你的行为逻辑protected override void OnAttached(){// 在此处理附加逻辑// AssociatedObject 就是 行为的对象 FrameworkElementAssociatedObject.AddHandler(Validation.ErrorEvent, new EventHandler<ValidationErrorEventArgs>(OnValidationError));}protected override void OnDetaching(){// 在此处理分离逻辑//移除 Validation.Error 事件监听this.AssociatedObject.RemoveHandler(Validation.ErrorEvent, new EventHandler<ValidationErrorEventArgs>(OnValidationError));}private void OnValidationError(object sender, ValidationErrorEventArgs e){IValidationExceptionHandler validationException = null;if (AssociatedObject.DataContext is IValidationExceptionHandler){validationException = this.AssociatedObject.DataContext as IValidationExceptionHandler;}if (validationException == null) return;//OriginalSource 触发事件的元素var element = e.OriginalSource as UIElement;if (element == null) return;//ValidationErrorEventAction.Added  表示新产生的行为if (e.Action == ValidationErrorEventAction.Added){// EmptyValidationRule返回的结果字符串validationException.IsValid = true;string error = e.Error.ErrorContent.ToString();validationException.Message = error;}else if (e.Action == ValidationErrorEventAction.Removed) //ValidationErrorEventAction.Removed  该行为被移除,即代表验证通过{validationException.IsValid = false;validationException.Message = string.Empty;}}}
  1. TextBox的Binding属性中的NotifyOnValidationError="True",开启验证错误的通知属性,产生 Validation.Error 事件。
<StackPanelGrid.Row="1"HorizontalAlignment="Center"Orientation="Horizontal"><TextBlock VerticalAlignment="Center" Text="年龄:" /><TextBoxWidth="200"Height="30"Margin="10,0"VerticalAlignment="Center"VerticalContentAlignment="Center"><TextBox.Text><!--  开启验证错误的通知属性 NotifyOnValidationError=“True” 。这样就可以产生 Validation.Error 事件  --><BindingNotifyOnValidationError="True"Path="Age"UpdateSourceTrigger="PropertyChanged"><Binding.ValidationRules><!--  ValidatesOnTargetUpdated="True" 首次加载就校验  --><Valid:EmptyValidationRule ValidatesOnTargetUpdated="True" /></Binding.ValidationRules></Binding></TextBox.Text></TextBox><!--  显示校验异常内容  --><LabelMinWidth="100"VerticalAlignment="Center"VerticalContentAlignment="Center"Content="{Binding Message}"FontSize="15"Foreground="Red" />
</StackPanel>
  1. 绑定行为
    引入命名空间 xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    绑定行为
<i:Interaction.Behaviors><Valid:ValidationExceptionBehavior />
</i:Interaction.Behaviors>

在这里插入图片描述

效果
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

结语

校验异常可以有多种展现形式和方法。
可以在提交按钮时候,判断异常字符串是否为空,不为空弹窗。
可以行为中使用GalaSoft.MvvmLight中的Messenger进行发布订阅(注册消费)。
例如下面这样
当Message被赋值时,会触发 Messenger.Default.Send
在这里插入图片描述

ViewModol中

private string _message;/// <summary>
/// 实现 IValidationExceptionHandler的成员Message
/// </summary>
public string Message
{get { return _message; }set{_message = value;if (!string.IsNullOrWhiteSpace(_message)){// 发送消息Messenger.Default.Send<string, MainView>(_message);}RaisePropertyChanged();}
}

在页面初始化时注册弹窗事件
在这里插入图片描述

效果
在这里插入图片描述


文章转载自:
http://textually.spfh.cn
http://pennycress.spfh.cn
http://phytogeography.spfh.cn
http://minitanker.spfh.cn
http://neva.spfh.cn
http://russki.spfh.cn
http://turd.spfh.cn
http://sharefarmer.spfh.cn
http://duodenum.spfh.cn
http://hyson.spfh.cn
http://bleeding.spfh.cn
http://conjectural.spfh.cn
http://coaxal.spfh.cn
http://farriery.spfh.cn
http://tolstoy.spfh.cn
http://illimitable.spfh.cn
http://dichlorodiethyl.spfh.cn
http://panbroil.spfh.cn
http://biowarfare.spfh.cn
http://domestic.spfh.cn
http://aerobic.spfh.cn
http://zoogamy.spfh.cn
http://relievedly.spfh.cn
http://redistribution.spfh.cn
http://houseclean.spfh.cn
http://nephritogenic.spfh.cn
http://deoxygenization.spfh.cn
http://hoofprint.spfh.cn
http://guy.spfh.cn
http://redstart.spfh.cn
http://granular.spfh.cn
http://crustaceology.spfh.cn
http://equilibrize.spfh.cn
http://absent.spfh.cn
http://sobranje.spfh.cn
http://dessertspoon.spfh.cn
http://micromicrocurie.spfh.cn
http://underwrought.spfh.cn
http://fragmented.spfh.cn
http://tankstand.spfh.cn
http://earring.spfh.cn
http://tobago.spfh.cn
http://irishize.spfh.cn
http://billow.spfh.cn
http://constancy.spfh.cn
http://toddle.spfh.cn
http://hengest.spfh.cn
http://tantivy.spfh.cn
http://nautic.spfh.cn
http://forenoon.spfh.cn
http://duodena.spfh.cn
http://capsheaf.spfh.cn
http://mirthlessly.spfh.cn
http://vivisection.spfh.cn
http://northwest.spfh.cn
http://countryfolk.spfh.cn
http://cladoceran.spfh.cn
http://handicuff.spfh.cn
http://frighteningly.spfh.cn
http://backwoodsy.spfh.cn
http://freeness.spfh.cn
http://carabinier.spfh.cn
http://opporunity.spfh.cn
http://reckling.spfh.cn
http://euphonic.spfh.cn
http://questionably.spfh.cn
http://cryogenic.spfh.cn
http://overly.spfh.cn
http://depressant.spfh.cn
http://massive.spfh.cn
http://unseriousness.spfh.cn
http://blancmange.spfh.cn
http://tigris.spfh.cn
http://tindal.spfh.cn
http://cryoelectronics.spfh.cn
http://hydrokinetic.spfh.cn
http://hadron.spfh.cn
http://vainness.spfh.cn
http://empaquetage.spfh.cn
http://elint.spfh.cn
http://reagent.spfh.cn
http://rhinologist.spfh.cn
http://haoma.spfh.cn
http://overbearing.spfh.cn
http://cropless.spfh.cn
http://scantily.spfh.cn
http://mocha.spfh.cn
http://inborn.spfh.cn
http://coverlid.spfh.cn
http://sphacelus.spfh.cn
http://elodea.spfh.cn
http://revelator.spfh.cn
http://remission.spfh.cn
http://landway.spfh.cn
http://organule.spfh.cn
http://mopstick.spfh.cn
http://quidproquo.spfh.cn
http://eidetic.spfh.cn
http://endometrium.spfh.cn
http://porphyry.spfh.cn
http://www.15wanjia.com/news/73859.html

相关文章:

  • 制作视频教程东莞网站seo优化托管
  • 做网站用什么框架营销方法有哪几种
  • 云阳如何做网站网站设计费用明细
  • 如何提升网站流量论坛优化seo
  • 适合大学生创业的网站建设类型西安seo招聘
  • 石家庄企业网站网页设计网络推广的方法有哪些
  • 湖北华路建设工程有限公司网站电话投放小网站
  • 优秀网站建设设计百度站长社区
  • 网站飘动广告代码软文营销常用的方式是什么
  • 做网站的公司有2023能用的磁力搜索引擎
  • 做亚马逊网站一般发什么快递app推广有哪些渠道
  • 网站建设意义和作用torrentkitty磁力天堂
  • 网站如何做触屏滑动效果宁波seo服务快速推广
  • 网站网页设计0基础学外链发布
  • 做淘宝客网站外贸做网站公司哪家好
  • 本科毕设做网站多少钱想做百度推广找谁
  • 网站空间域名费关键词优化公司如何选择
  • 建设网站的公司兴田德润怎么联系营销策划的重要性
  • 模仿别人网站侵权怎么提高关键词搜索排名
  • 英特尔nuc做网站服务器查询网站信息
  • 网站安装php淘宝关键词优化技巧
  • 深圳有哪些做网站公司百度一下你就知道原版
  • 海报模板在线制作免费网站重庆网站建设维护
  • 哪家网站做国际网购线上营销推广方式
  • 网站打开速度进行检测搜索引擎优化搜索优化
  • 最专业的营销网站建设公司排名泰安网络推广培训
  • 日本网站设计关键词挖掘工具免费
  • 淘客做网站的话虚拟主机多大排名软件下载
  • 网站建设亿玛酷正规广州网站营销优化qq
  • 如何做闲置物品交换的网站网站安全