2012-03-23 4 views
0

WPF에서 계층 적 트리 뷰가 있습니다. viewmodel을 사용하여 이벤트 바인딩을 위해 http://marlongrech.wordpress.com/2008/12/13/attachedcommandbehavior-v2-aka-acb/을 사용합니다.TreeView의 상위 조상을 명령 매개 변수로 사용

트리 뷰에서 항목을 이중 클릭하면 항상 루트 유형을 명령 매개 변수로 전달하려고합니다.

예 :

..B
.... C
D ..E

내가 'A', 'B'또는 'C'내가 원하는 클릭
명령 매개 변수로 'A'. 'D'또는 'E'를 클릭하면 명령 매개 변수로 'D'를 원합니다. .. 내가 RelativeSource 바인딩해야 할 가정

<Setter Property="acb:CommandBehavior.Event" Value="MouseDoubleClick"/> 
    <Setter Property="acb:CommandBehavior.Command" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.SomeCommand}"/> 
    <Setter Property="acb:CommandBehavior.CommandParameter" Value="{Binding}"/> 

, 나는 그것을 알아낼 수 없습니다

:

는 지금까지이 항상 항목이 commandparameter로 클릭 전송 한 것입니다

감사

미셸 내 지식

+0

각 항목이 중첩 된 수준을 알고있는 경우 "바인딩 RelativeSource = {RelativeSource 모드 = FindAncestor, AncestorType = {x : Type TreeViewItem}, AncestorLevel = 2}, Path = DataContext.AProperty}"를 사용할 수 있습니다. AncestorLevel을 올바르게 설정해야합니다. – Phil

답변

1

당신이 원하는 표현에 해당하는 바인딩을 만들 수 없습니다, 당신은 CUR을 통과 나을 수 있습니다 항목을 매개 변수로 임대하고 명령 코드에서 루트 노드를 찾습니다.

관련 문제