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

网站如何做网页查询网站设计过程中需要注意的问题

网站如何做网页查询,网站设计过程中需要注意的问题,广州外贸网站建设开发,公众平台的微信网站开发一、作用 将Window GUI的运行机理从 “事件驱动” 转变为 “数据驱动”。将UI界面与业务逻辑解耦#xff0c;使得改动一个而无需改动另一个。数据逻辑层自成体系#xff0c;使得无需借助UI也可进行单元测试。 二、基础 1. Binding源模板 Binding包括源与目标#xff0c;源…一、作用 将Window GUI的运行机理从 “事件驱动” 转变为 “数据驱动”。将UI界面与业务逻辑解耦使得改动一个而无需改动另一个。数据逻辑层自成体系使得无需借助UI也可进行单元测试。 二、基础 1. Binding源模板 Binding包括源与目标源通常为逻辑层的类对象属性目标通常为展示层的控件属性。 那么如何让类对象属性成为绑定源呢通过类对象实现INoticePropertyChanged接口并对类对象属性的Set语句加上PropertyChange事件这个事件是由INoticePropertyChanged接口定义的。 如何让控件属性成为绑定目标通过创建Binding类对象并确定Source为哪个类对象实例Path为类对象实例的哪个属性最终通过BindingOperations.SetBinding实现目的控件属性到数据源的绑定。 2. 把控件作为Binding源的Binding标记扩展 Text “{Binding (Path)Value,ElementNameslider1}” 3. Binding的常规属性 Mode控制方向 TwoWay双向绑定源修改更新到目的目的修改更新到源 OneWay单向绑定源修改更新到目的 OneTime单次绑定程序启动时源与目的数据仅绑定一次 OneWayToSource单向绑定目的修改更新到源 Default 根据具体控件而定可编辑的为TwoWay不可编辑的为OneWay UpdataSourceTrigger数据更新时机 PropertyChanged 源的值发生改变后立即更新 LostFocus 绑定源的控件失焦后才同步更新 Explict 不会自动更新除非自己调用UpdateSource Default 根据具体控件而定如TextBox为LostFocus 三、路径 1. 控件某个属性 控件的某个属性Text”{Binding PathValue, ElementNameslider1}” 多级路径Text”{Binding PathText1.Length, ElementNametextBox1}” 集合类型的索引器Text”{Binding PathText[3], ElementNametextBox1}”2. 集合或DataView的默认元素 Text”{Binding Path/, ElementNamestringList}” Text”{Binding Path/Length, ElementNamestringList}” Text”{Binding Path/[2], ElementNamestringList}”3. 集合元素的属性仍是一个集合 Text”{Binding Path/Name, ElementNamecountryList}” Text”{Binding Path/ProvinceList.Name, ElementNamecountryList}” Text”{Binding Path/ ProvinceList/CityList.Name, ElementNamecountryList}”4. 没有Path的Binding Binding源本身就是数据且不需要Path来指明如string和int等基本类型Xaml中可以直接Path. ,或者不指明Path Text{Binding Path.,Source{StaticResource ResouceKeymyString}} Text{Binding Source{StaticResource ResouceKeymyString}}CShape中只能Path. , 但不能不写 this.textBlock1.SetBinding(TextBlock.TextProperty, new Binding(.){SourcemyString}) 四、源 1. 没有Source的Binding 当一个Binding只知道自己的Path而不知道自己的Source时它会沿着UI元素树一路向树根找过去每路过一个节点就会看这个结点的DataContext是否具有Path所指定的属性。 之所以会有“Binding沿着UI元素树向上找”的错觉是因为DataContext是一个依赖属性依赖属性有一个很重要的特点就是当你没有为控件的某个依赖属性显式赋值时控件会把自己容器的属性值“借过来”当作自己的属性值实际上是属性值沿着UI元素树向下传递了。 使用场景 1.当UI上的多个控件都使用Binding关注同一个对象时 2.当作为Source对象不能被直接访问时如B窗体想把A窗体内的private控件作为Binding源时。 StackPanelStackPanel.DataContextsys:StringHello DataContext/sys;String/StackPanel.DataContext /StackPanel GridStackPanelTextBlock Text{Binding} //这里继承Hello DataContext/StackPanel /Grid2. 使用集合对象作为源 注意使用集合类型作为列表控件的ItemSource时一般会考虑使用ObservableCollection代替List因为ObservableCollection类实现了InotifyCollectionChanged和InotifyPropertyChange接口能把集合的变化立刻通知显示它的列表控件改变会立刻显现出来。 .xaml ListBox ItemSource{Binding stuList} DisplayMemberPathName.cs ListStudent stuListnew ListStudent(); stuList.Add(new Student{Id,Name,Age});3. 使用DataTable作为源 使用DataTable作为数据源this.listBoxStudents.ItemSourcedt.DefaultView;若要展示DataTable的每个元素则 GridViewGridViewColumn Header”Id” Width”60” DisplayMemberBinding”{Binding Id}”/… /GridView注意可以使用DataTable对象的DefaultView属性作为ItemSource但是不可以直接使用DataTable对象作为ItemSource。 除非将DataTable对象放在一个对象的DataContext属性里并把ItemSource与一个既没有指定Source又没有指定Path的Binding关联起来Binding能自动找到它的DefaultView并当作自己的Source来使用。4. 使用XML数据作为源 .xml StudentListStudent Id1NameTime/Name/Student /StudentList.xaml LisView DataContextxdp ItemSource{Binding}LiveView.ViewGridViewGridViewColumn Header”Id” Width”80” DisplayMemberBinding”{Binding XPathId}”/GridViewColumn Header”Name” Width”120”DisplayMemberBinding”{Binding XPathName}”//GridView/LiveView,View /ListView 注意使用XML数据作为Binding的源时将使用Xpath属性而不是Path属性来指定数据的来源。 使用符号加字符串表示的是XML元素的Attribute不加符号的字符串表示的是子级元素。.cs XmlDocument docnew XmlDocument(); doc.Load(D;\RawData.xml); XmlDataProvider xdpnew XmlDataProvider(); xdp.Documentdoc; xdp.XPath”/StudentList/Student“; 5. 使用LINQ检索结果作为源 使用LINQ可以方便地操作集合对象、DataTable对象和XML对象而不必把好几层foreach循环嵌套在一起。 / 集合 / DataTable对象 / 查询XML 6. 使用ObjectDataProvider对象作为源 有时很难保证一个类所有数据都使用属性暴露出来比如我们需要的数据可能是方法的返回值。 注意前两个TextBox在Binding的数据流向上做了限制因为ObjectDataProvider的MethodParameters不是依赖属性不能作为Binding的目标。 7. 使用Binding的RelativeSource 有时候我们不能确定作为Source的对象叫什么名字但知道它与作为Binding目标的对象在UI布局上有相对关系。Text”{Binding RelativeSource{RelativeSource FindAncestor, AncestorType{x:Type Grid, AncestorLevel1}, PathName}”RelativeSource类的Mode属性的类型是RelativeSourceMode枚举取值有PreviousData、TemplateParent、Self和FindAncestor。五、数据转换与校验 1. 转换器 实现IValueConverter接口 public interface IValueConverter {object Convert(object value,Type targetType,object parameter,CultureInfo culture);object ConvertBack(object value,Type targetType,object parameter,CultureInfo culture); }举例 public class IntToBool : IValueConverter {private static readonly LazyIntToBool LazyInstance new LazyIntToBool(() new IntToBool());public static IntToBool Instance LazyInstance.Value;public object Convert(object value, Type targetType, object parameter, CultureInfo culture){try{if (value ! null){int.TryParse(value.ToString(), out var va1);return va1 0;}}catch (Exception ex){}return true;}public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture){return null;}}2. 多路绑定 有时UI需要显示的信息由不止一个数据来源决定则需要使用到MultiBinding。MultiBinding具有一个名为Bindings的属性类型为Collection通过该属性可以将在这里插入代码片一组Binding对象聚合起来每个Binding对象拥有自己的数据校验与转换机制它们汇集起来的数据将共同决定传往MultiBinding目标的数据。 - 设置多路绑定.xaml ButtonButton.IsEnabledMultiBinding Converter{x:Static vt:LogonMultiBindingConverter.Instance} ModeBindingMode.OneWayBinding PathText,Elementtext1Box1Binding PathText,Elementtext1Box2Binding PathText,Elementtext1Box3Binding PathText,Elementtext1Box4/MultiBinding/Button.IsEnabled /Button.cs Binding b1new Binding(Text){Sourcethis.textBox1}; Binding b2new Binding(Text){Sourcethis.textBox2}; Binding b3new Binding(Text){Sourcethis.textBox3}; Binding b4new Binding(Text){Sourcethis.textBox4};MultiBinding mb new MultiBinding(){ModeBindingMode.OneWay}; mb.Binding.Add(b1); mb.Binding.Add(b2); mb.Binding.Add(b3); mb.Binding.Add(b4); mb.Converternew LogonMultiBindingConverter();this.button1.SetBinding(Button.IsEnabledPropery,mb);将多个Binding对象加入属性Bindings中然后设计MultiBinding的转换器通过实现IMultiValueConverter接口对object[] values进行索引来获取每个Binding对象传入的value对它们进行处理之后共同决定MultiBinding的转换结果。 - 定义多路转换器 public class LogonMultiBindingConverter:IMultiValueConverter {private static readonly LazyLogonMultiBindingConverter LazyInstance new LazyLogonMultiBindingConverter(() new LogonMultiBindingConverter());public static IntToBool Instance LazyInstance.Value;public object Convert(object[] values,Type targetType,object parameter,Cultureinfo culture){if(!values.Caststring().Any(textstring.IsNullOrEmpty(text) value[0].ToString()values[1].ToString()) value[2].ToString()values[3].ToString()){return ture;}return false;} }3. 校验 Binding的ValidationRules属性类型是Collection即可为每个Binding设置多个数据校验条件。ValidationRule是抽象类需要实现它的Validate方法当符合校验时返回ValidationResult类型的属性IsValid为true否则为false。 public class RangeValidationRule:ValidationRule {LazyRangeValidationRule instancenew LazyRangeValidationRule(new RangeValidationRule());public override ValidationResult Validate(object value,System.Globalization.CultureInfo cultureInfo){double d0;if(double.TryParse(value.ToString(),out d){if(d0 d100){return new ValidationResult(true,null);}return new ValidationResult(false,Validation Failed);} }Binding进行校验时的默认行为是认为Source的数据总是正确的而Target数据有用户操作所以才可能出现错误。若想校验Target数据的同时也校验Source数据则需要将校验条件ValidationRule的子类的ValidatesOnTargetUpdated属性设为true。 .xaml TextBox Text{Binding ValidationRules{x:Static RangeValidationRule.Instance}}.cs Binding bindingnew Binding(Value){Sourcethis.slider1}; binding,UpdateSourceTriggerUpdateSourceTrigger.PropertyChanged; RangeValidationRule rvrnew RangeValidationRule(); binding,ValidationRules.Add(rvr); this.textBox1.SetBinding(TextBox.TextProperty,binding);
http://www.hkea.cn/news/14337019/

相关文章:

  • 手机网站跳转代码凡客诚品 正品官网
  • 网站项目下载室内装修公司排行
  • 网站建设实验心得网站怎么做翻页
  • 湛江有网站的公司名称东莞市新闻头条
  • 专做商品折扣的网站鄂尔多斯 网站建设
  • 常德做网站公司佳城建站 网站
  • 合肥重点工程建设局网站要素的优化设计
  • 网站排名优化策略重庆卓光科技有限公司
  • 如何在虚拟空间上做多个网站制作一个自适应网站源码
  • 邳州建设银行招聘网站WordPress搭建聊天室
  • 网站界面设计套题好创意网站有哪些方面
  • 重庆价格低建设网站公司网站怎么做跳转链接
  • 网站开发和美工的区别网站建设情况存在问题
  • 网站建设 交单流程狗和女人做的网站
  • 国外房屋设计网站艺术网页设计欣赏
  • 开封建设网站电子商城网站设计公司哪个好
  • 沈阳专业制作网站公司吗坊子网站建设
  • 网站制作模板软件个人网站有备案吗
  • .php的网站是怎么做的绍兴网络公司网站建设
  • 潮州企业网站建设广东建设工程注册中心网站
  • 做网站地图邮什么好处重庆教育建设集团有限公司网站
  • 餐饮连锁网站建设游戏公司招聘网站
  • 茂名网站建设哪家强北京黑马培训机构怎么样
  • 如何检测网站是否安全0基础建站教程
  • 重庆市设计公司网站做封面怎么把网站加上去
  • 鲁权屯网站建设wordpress安装404
  • 宁波网站建设营销定制房地产破了后国家会怎样
  • 网站的设计路线开网店卖什么产品比较好
  • 宜昌市网站建设外贸建站 wordpress
  • ui动效网站北京个人网站设计