2010-04-20 2 views
1

바인딩에 문제가 있습니다. UserControl (intellibox from codeplex)을 사용하고 싶지만 출력 창에 오류 메시지 만 표시됩니다.WPF binding Ancestor

같아요
{Binding Path=ShowResults, RelativeSource={RelativeSource FindAncestor, 
AncestorType={x:Type UserControl}}} 

는이 다음과 같이 다음은 IntelliBox 컨트롤에 바인딩

System.Windows.Data Error: 4 : Cannot find source for binding with reference 
    'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.UserControl', 
    AncestorLevel='1''. BindingExpression:Path=ShowResults; DataItem=null; 
    target element is 'Popup' (Name='IntelliboxPopup1'); 
    target property is 'IsOpen' (type 'Boolean') 

가 정의됩니다 기본적으로 내가 물건을 다음 얻을 출력 창에서

window grid ... stuff ... usercontrol (self written) ... stuff ... usercontrol (IntelliBox) 

이 문제, 중첩 withing usercontrols - 어떻게 해결이 오류가 발생합니까?

감사합니다.

답변

2

두 가지 질문이 있습니다. 첫째, 이것은 당신이 당신의 사용을 위해 쓴 Binding입니까? 아니면 사용하고있는 UserControl 내부에서 즉시 사용할 수있는 것입니까? 둘째, Intellibox 또는 "자체 작성된"UserControl에 바인딩하려고합니까?

당신이 사용하기 위해 쓴 Binding이라고 가정합니다. (Intellibox에 대한 지식이 없으므로 어디에서 수정해야할지 모르겠습니다) 시도 할 수있는 몇 가지 해결책이 있습니다.

먼저, 조상에 바인딩 할 때 정확한 조상 유형을 사용해보십시오. 예를 들어 Intellibox에 바인딩하는 경우 AncestorType={x:Type Intellibox}을 사용합니다. 그렇지 않으면 AncestorType={x:Type <YourType>}을 사용하십시오. 귀하의 바인딩이 덜 모호한 이런 식으로 될 것입니다. , HTH -

{Binding Path=ShowResults, 
     ElementName=BindSource} 

:

둘째, 아마이 경우 가장 좋은 대답은, 대상에 x:Name="BindSource (or whatever)"을 설정하고 바인딩 구문을 사용하여 이름하여 원하는 컨트롤에 바인딩하는 것입니다 Dusty

+0

안녕하세요, 귀하의 답변에 감사드립니다. 문제는 내가 사용하려고 시도한 IntellBox 컨트롤에 있습니다 (코드 플렉스에서 가져올 수 있음). 나는 이름으로 바인드를 시도 할 것이다. 다시 한번 감사드립니다! – JerryVienna