[WPF Bug清单]之(12)——与自定义Attached Property相关的Binding Path运行时错误
2010-01-15 22:26
393 查看
我们都知道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”这个关键词省略掉,然而就在Binding到custom attached property时屡试都爽!可就是不知道问题出在哪。最后无意中发现加上“Path”就好了,然后就想问候一下微软的Dev和QA。
好消息是这个Bug在.NET 4.0 Beta2中已经Fix了。毕竟整个XAML解析都重写了。
{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”这个关键词省略掉,然而就在Binding到custom attached property时屡试都爽!可就是不知道问题出在哪。最后无意中发现加上“Path”就好了,然后就想问候一下微软的Dev和QA。
好消息是这个Bug在.NET 4.0 Beta2中已经Fix了。毕竟整个XAML解析都重写了。
相关文章推荐
- [WPF Bug清单]之(6)——Button的IsCancel属性失效
- [WPF Bug清单]之(2)——RadioButton的IsChecked绑定失效
- [WPF Bug清单]之(10)——CheckBox在不同主题下具有不同的行为
- [WPF Bug清单]之(5)——隐藏模态对话框后变成非模态
- [WPF Bug清单]之(7)——顽固的Error Template
- wpf RadioButton控件的一个bug,onpropertychanged后会修改旧属性的值
- Attached Property In WPF
- [WPF Bug清单]之(3)——暗中创建文件的打开文件对话框
- WPF Bug清单之(13)——应该出现却没有出现的ListView水平滚动条
- WPF中的Attached Property
- [WPF Bug清单]之(11)——错位的RenderTransform动画
- WPF 自定义NotifyPropertyChanged
- [WPF Bug清单]之(9)——消失的光标
- [WPF Bug清单]之(4)——点击RadioButton的空白没有反应
- [WPF Bug清单]之(8)——RowDefinition中MaxHeight在一定条件下失效
- WPF Bug清单之(13)——应该出现却没有出现的ListView水平滚动条
- 描述相关WPF自定义路由事件知识
- WPF - 属性系统 - APaas(AttachedProperty as a service)
- 自定义ISAPI Filter中发现的一个与Keep-Alive相关的Bug
- [WPF Bug清单](序)与之(1)——可以多选的单选ListBox