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

大理网站建设沛宣做设计常用网站有哪些

大理网站建设沛宣,做设计常用网站有哪些,最全微信小程序名单,IDC网站用什么软件建在上一次的文章WPF OnApplyTemplate 不执行 或者执行滞后的疑惑谈到怎么正确的开发自定义控件#xff0c;我们控件的样式中#xff0c;属性的绑定一般都是用TemplateBinding来完成,如下一个基本的按钮样式#xff1a; Style x:KeySimpleButton TargetType我们控件的样式中属性的绑定一般都是用TemplateBinding来完成,如下一个基本的按钮样式 Style x:KeySimpleButton TargetType{x:Type Button} BasedOn{x:Null}Setter PropertyFocusVisualStyle Value{DynamicResource SimpleButtonFocusVisual}/Setter PropertyBackground Value{DynamicResource NormalBrush}/Setter PropertyBorderBrush Value{DynamicResource NormalBorderBrush}/Setter PropertyTemplateSetter.ValueControlTemplate TargetType{x:Type Button}!-- We use Grid as a root because it is easy to add more elements to customize the button --Grid x:NameGridBorder x:NameBorder Background{TemplateBinding Background} BorderBrush{TemplateBinding BorderBrush} BorderThickness{TemplateBinding BorderThickness} Padding{TemplateBinding Padding}/!-- Content Presenter is where the text content etc is placed by the control --!-- The bindings are useful so that the control can be parameterized without editing the template --ContentPresenter HorizontalAlignment{TemplateBinding HorizontalContentAlignment} Margin{TemplateBinding Padding} VerticalAlignment{TemplateBinding VerticalContentAlignment} RecognizesAccessKeyTrue//Grid!--Each state sets a brush on the Border in the template --ControlTemplate.TriggersTrigger PropertyIsKeyboardFocused ValuetrueSetter PropertyBorderBrush Value{DynamicResource DefaultedBorderBrush} TargetNameBorder//TriggerTrigger PropertyIsMouseOver ValuetrueSetter PropertyBackground Value{DynamicResource MouseOverBrush} TargetNameBorder//TriggerTrigger PropertyIsPressed ValuetrueSetter PropertyBackground Value{DynamicResource PressedBrush} TargetNameBorder/Setter PropertyBorderBrush Value{DynamicResource PressedBorderBrush} TargetNameBorder//TriggerTrigger PropertyIsEnabled Valuetrue/Trigger PropertyIsEnabled ValuefalseSetter PropertyBackground Value{DynamicResource DisabledBackgroundBrush} TargetNameBorder/Setter PropertyBorderBrush Value{DynamicResource DisabledBorderBrush} TargetNameBorder/Setter PropertyForeground Value{DynamicResource DisabledForegroundBrush}//Trigger/ControlTemplate.Triggers/ControlTemplate/Setter.Value/Setter /Style 我们看到许多属性都是用TemplateBinding来完成的也就是我们在使用控件和开发自定义控件时都能够做到数据的展示和数据的行为分开使用数据驱动UI的思想对于较复杂行为的控件我们也可以在OnApplyTemplate方法中通过GetTemplateChild方法来获取到当然这个方法的执行时机是必须在布局过程中如果在这之前就使用了内部的控件那么必然会报Null错误。 所以一般的样式开发中都是用TemplateBinding来完成说说今天的遭遇。我就是开发一个分页控件点击上一页下一页的时候当前的页码要能够跟着变化。显示这个页码的控件那就是TextBlockTemplateBinding了PageIndex依赖属性。控件的后台代码中对上一页下一页的事件就是修改PageIndex的值。运行起来页码不会跟着变化好修改成Binding方式如下 TextBlock Text{Binding RelativeSource{RelativeSource TemplatedParent},PathPageIndex}/TextBlock 这样能够正常工作了。但是WPF自家的控件用的都是TemplateBinding都没这问题不甘心继续网上找资料发现一篇说是自定义的依赖属性使用TemplateBinding就是有问题的这种bug微软怎么能不发现呢并且这都.Net4.5了内心感觉一定不是这样的终于啊找到问题所在了并且是在一篇排版杂乱无章的小博客中找到的。 TemplateBinding作为一种性能优化后的Binding使用据说是Binding比较耗资源这个没有求证过但是我的程序中那么多Binding运行起来也不觉得慢啊或者说是用在模板中的一种Binding优化方式。既然是优化过的那么它就会少一些东西其中一个是数据流动的方向。TemplateBinding是单方向的即数据源到目标的方向。这也解释了TreeViewItem官方的样式中那个三角形的小箭头它对于是否展开IsExpanded属性的属性绑定用的就不是TempalteBinding因为他不能反过去更新数据源啊。 Style x:KeySimpleTreeViewItem d:IsControlPartTrue TargetType{x:Type TreeViewItem}Setter PropertyBackground ValueTransparent/Setter PropertyHorizontalContentAlignment Value{Binding PathHorizontalContentAlignment, RelativeSource{RelativeSource AncestorType{x:Type ItemsControl}}}/Setter PropertyVerticalContentAlignment Value{Binding PathVerticalContentAlignment, RelativeSource{RelativeSource AncestorType{x:Type ItemsControl}}}/Setter PropertyPadding Value1,0,0,0/Setter PropertyTemplateSetter.ValueControlTemplate TargetType{x:Type TreeViewItem}GridGrid.ColumnDefinitionsColumnDefinition MinWidth19 WidthAuto/ColumnDefinition WidthAuto/ColumnDefinition Width*//Grid.ColumnDefinitionsGrid.RowDefinitionsRowDefinition HeightAuto/RowDefinition//Grid.RowDefinitions!--注意这里--ToggleButton x:NameExpander Style{DynamicResource SimpleTreeViewItemToggleButton} IsChecked{Binding PathIsExpanded, RelativeSource{RelativeSource TemplatedParent}} ClickModePress/Border Grid.Column1 x:NameSelection_Border Background{TemplateBinding Background} BorderBrush{TemplateBinding BorderBrush} BorderThickness{TemplateBinding BorderThickness} Padding{TemplateBinding Padding}ContentPresenter HorizontalAlignment{TemplateBinding HorizontalContentAlignment} x:NamePART_Header ContentSourceHeader//BorderItemsPresenter Grid.Column1 Grid.ColumnSpan2 Grid.Row1 x:NameItemsHost//GridControlTemplate.TriggersTrigger PropertyIsExpanded ValuefalseSetter PropertyVisibility ValueCollapsed TargetNameItemsHost//TriggerTrigger PropertyHasItems ValuefalseSetter PropertyVisibility ValueHidden TargetNameExpander//TriggerTrigger PropertyIsSelected ValuetrueSetter PropertyBackground Value{DynamicResource {x:Static SystemColors.HighlightBrushKey}} TargetNameSelection_Border/Setter PropertyForeground Value{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}//TriggerMultiTriggerMultiTrigger.ConditionsCondition PropertyIsSelected Valuetrue/Condition PropertyIsSelectionActive Valuefalse//MultiTrigger.ConditionsSetter PropertyBackground Valuered TargetNameSelection_Border/Setter PropertyForeground Value{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}//MultiTriggerTrigger PropertyIsEnabled ValuefalseSetter PropertyForeground Value{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}//Trigger/ControlTemplate.Triggers/ControlTemplate/Setter.Value/Setter /Style 但是在分页控件的这个页码属性上是不需要反方向更新数据源这个功能的。所以问题也不是这儿但必须注意这一点开发自定义控件的时候非常重要。 另外一个区别就是ConverterWPF中的Binding都是能够通过Converter来转换数据的所以不管是TemplateBinding还是Binding都是够使用Converter来设置转换器区别在于没有设置转换器的情况下例如将int类型的数据绑定到TextBox的Text属性上Binding会将值转换成字符串来显示然而TemplateBinding就不会这就是页码不能显示也不会变化的原因。我立马弄了一个字符串类型页码依赖属性TemplateBinding到这个Text属性上可以工作了。但不会这么傻再写一个转换器给TemplateBinding这也是能够工作的。所以当数据源的类型和目标的类型不一致时TemplateBinding需要自己写转换器来完成。 总结一下TemplateBinding与Binding区别 1TemplateBinding只是单方向的数据绑定 2TemplateBinding不会自动转换数据类型 转载于:https://www.cnblogs.com/HelloMyWorld/p/6744894.html
http://www.sadfv.cn/news/18703/

相关文章:

  • 放心网站推广优化咨询wordpress 文章之显示标题
  • 帮别人做网站赚多少钱网站访问对应二级域名
  • 网站描述范例武进建设局网站进不去
  • 礼品网站建设公司现在个人做网站还能盈利吗
  • 网站开发工程师薪酬待遇西安做建站的公司
  • 电气网站建设小程序发布流程
  • 网站建设注册哪类商标网站页面设计如何快速定稿
  • 服务器网站开发手机网站登录模板
  • 深圳创新网站建设常州网站制作推广
  • 2015个人备案网站论坛怎么做企业网站推广的方法
  • 建湖做网站的公司景安安装wordpress
  • 局机关建设网站的意义做设计的网站定制
  • 织梦网站关掉wap品牌建设让
  • 校园网站建设的可行性分析沧州网站制作多少钱
  • 建站行业成为买方市场办公网络建设项目商务要求
  • 做网站搞友情链接无锡百度
  • 如何免费做网站商家做网站的优点
  • 建立网站需要多少钱八寇湖南岚鸿团队网站页面优化方案
  • 网站会员系统wordpress推广普通话的重要性
  • 网站规划结构电子商务网站建设过程范文
  • 河南城乡建设部网站Wordpress页面手机不适配
  • 做网站首选科远网络网站如何设置404页面
  • 江苏纬信网站建设郑州网络营销网站
  • 做网站的公司哪好众筹网站开发分析报告
  • 网站开发前端要学什么软件深圳找网站建设
  • 软件通网站建设免费一级域名注册教程
  • 宁波网络推广产品服务天津seo托管
  • 深圳鼎诚网站建设企业手机版网站
  • 安庆网站建设为长沙亚町设计
  • 营销网站如何建设网站做那个效果好