0
我想在代码(C#)内的绑定声明中执行一个类型转换。这里的代码说明我的情况的快速块:TypeCast在绑定路径内
Binding aBinding = new Binding();
aBinding.Mode = BindingMode.OneTime;
aBinding.ElementName = "FullPagePageViewGrid";
//aBinding.Path = new PropertyPath("((IPageLayout)Children[0])"); // What I'd like to do - causes error
aBinding.Path = new PropertyPath("Children[0]");
aBinding.Converter = new IsSelectedTextBoldConverter();
this.aLabel.SetBinding(Label.ContentProperty, aBinding);
这是我收到的错误 - 这并不奇怪,VS抱怨没有找到路径:
System.Windows.Data Error: 39 : BindingExpression path error: '((IPageLayout)Children[0])' property not found on 'object' ''Grid' (Name='FullPagePageViewGrid')'. BindingExpression:Path=((IPageLayout)Children[0]); DataItem='Grid' (Name='FullPagePageViewGrid'); target element is 'Label' (Name='aLabel'); target property is 'Content' (type 'Object')
这就是我所害怕的。我能够成功地使用一个转换器,但想看看我能否直接连接它。谢谢! – Joel 2009-07-21 13:58:59