2011-09-21 33 views
0

當我的展開父展開時,我試圖展開一個子節點。在父視圖展開時父展開的時候展開子代

除非另有說明:(Child.IsExpanded == Parent.IsExpanded)

這似乎是正確的,但似乎並沒有工作:

<TreeView ItemsSource="{Binding}"> 
    <TreeView.ItemContainerStyle> 
     <Style TargetType="TreeViewItem"> 
      <Style.Triggers> 
       <DataTrigger Value="True" 
          Binding="{Binding Path=IsExpanded, 
          RelativeSource={RelativeSource 
          Mode=FindAncestor, 
          AncestorType={x:Type TreeViewItem}, 
          AncestorLevel=2}}"> 
        <Setter Property="IsExpanded" Value="True" /> 
       </DataTrigger> 
      </Style.Triggers> 
     </Style> 
    </TreeView.ItemContainerStyle> 
</TreeView> 

無論是做這個的:

<TreeView ItemsSource="{Binding}"> 
    <TreeView.ItemContainerStyle> 
     <Style TargetType="TreeViewItem"> 
      <Setter Property="IsExpanded" 
        Value="{Binding Path=IsExpanded, 
          RelativeSource={RelativeSource 
          Mode=FindAncestor, 
          AncestorType={x:Type TreeViewItem}, 
          AncestorLevel=2}}" /> 
     </Style> 
    </TreeView.ItemContainerStyle> 
</TreeView> 

這裏缺少什麼?

在此先感謝。

回答

1

兩者都適合我。如果您使用靜態TreeViewItems進行測試,請務必通過資源應用樣式,ItemContainerStyle僅與動態創建的容器相關。另請注意,用戶交互可能會設置本地值,覆蓋這些樣式。

+0

+1「我不知道」 –