2016-08-18 53 views

回答

1

TreeViewItem有一個屬性IsExpanded您可以將該屬性與您的ObservableCollection對象屬性綁定並從ViewModel處理它。

 <Style TargetType="{x:Type TreeViewItem}"> 
      <Setter Property="IsExpanded" Value="{Binding IsExpandedProp}" />     
     </Style> 

視圖模型

public bool IsExpandedProp 
    { 
     get { return _IsExpandedProp; } 
     set { _Values = _IsExpandedProp; NotifyPropertyChanged(); } 
    } 
+0

由於阿斌,它比我想象中的簡單。我甚至不使用mvvm模式,我只是將我的列表對象設置爲IsExpanded = true/false。 –

+0

根據你的問題,你的節點應該在某個時候停止擴展,以便從代碼中使用我的解決方案。 –

相關問題