I would like to perform a typecast within a binding declaration within code (C#). Here's a quick chunk of code illustrating my situation:
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);
Here's the error I receive - not surprisingly, VS complains about not finding the path :
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')