zoukankan      html  css  js  c++  java
  • [WPF Bug清单]之(12)——与自定义Attached Property相关的Binding Path运行时错误

    我们都知道DataBinding的格式是这样的:

    {Binding Path=PropertyName}

    其中的Path=这几个字是可以省略的。从而简写成:

    {Binding PropertyName}

    这个行为也在MSDN上面特别介绍过。

    本文所指“解析错误”是指:当Property自定义AttachedProperty时,第二种写法会产生运行时错误。如下代码所示:

    Demo Code
    <Window x:Class="BindingPathBug.DemoWindow"
            xmlns
    ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x
    ="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local
    ="clr-namespace:BindingPathBug"
            Title
    ="{Binding (ToolTipService.ToolTip), ElementName=button}"
            Height
    ="300" Width="300">
     
    <Button x:Name="button"
              ToolTipService.ToolTip
    ="Tooltip"
              Content
    ="{Binding (local:ContentService.Content), ElementName=button}"
              local:ContentService.Content
    ="Button Content"/>
    </Window>

    其中,第一个绑定是可以正确运行的。而第二个绑定是不能正确运行的。必须要写成下面这样才行。

    Content="{Binding Path=(local:ContentService.Content), ElementName=button}"

    这个应该是Binding Markup Extension的解析错误。整个程序可以从这里下载。

    有些人(包括我)在Binding中都会把“Path”这个关键词省略掉,然而就在Bindingcustom attached property时屡试都爽!可就是不知道问题出在哪。最后无意中发现加上“Path”就好了,然后就想问候一下微软的DevQA

    好消息是这个Bug.NET 4.0 Beta2中已经Fix了。毕竟整个XAML解析都重写了。

  • 相关阅读:
    html5和css3的新特性
    实现全选按钮的js代码
    window.location对象获取浏览器地址栏的地址信息
    珍爱网前端笔试题之九宫格的实现
    c# array arraylist list
    解决visual studio不能发现单元测试、无法运行单元测试的方法
    Linux 学习笔记
    C++语言学习
    C语言学习
    日志打印,设置开关类【编程技巧】
  • 原文地址:https://www.cnblogs.com/nankezhishi/p/bindingPathToAttachedPropertyBug.html
Copyright © 2011-2022 走看看