2009-07-21 3 views
0

코드 (C#) 내에서 바인딩 선언 내에서 형식 변환을 수행하고자합니다. 당연히 VS에 대한 경로를 찾지 못하는 불평 - 여기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); 

내가받을 오류 발생 :

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') 

답변

1

죄송합니다,하지만 당신은 그것을 할 수 없습니다 여기 내 상황을 보여주는 코드의 빠른 덩어리입니다 그런 식으로 경로는 "직접"있어야합니다. 그러나, 그것은 변환기가해야 할 입니다.; 당신은 당신이 필요로하는 모든 캐스팅을 수행하는 것을 제공해야합니다.

+0

그건 내가 두려워했던거야. 성공적으로 변환기를 사용할 수 있었지만 직접 연결 할 수 있는지 알고 싶었습니다. 감사! – Joel

관련 문제