AutoExpand treeview in WPF

前端 未结 5 2069
悲哀的现实
悲哀的现实 2021-02-06 21:04

Is there a way to automatically expand all nodes from a treeview in WPF? I searched and didn\'t even find an expand function in the treeview property.

Thanks

5条回答
  •  梦如初夏
    2021-02-06 21:30

    if you want expand manually you can try

    Xaml:

    
        
            
        
     
    

    c#:

    bool Expanded = false; 
    // The event subscription method (for a button click)
    private void ButtonExpand__Click(object sender, RoutedEventArgs e)
    {
        Expanded = !Expanded;
        Style Style = new Style
        {
            TargetType = typeof(TreeViewItem)
        };
    
        Style.Setters.Add(new Setter(TreeViewItem.IsExpandedProperty, Expanded));
        TreePeople.ItemContainerStyle = Style;
    }
    

提交回复
热议问题