Changing the styles at runtime in WPF

前端 未结 3 851
走了就别回头了
走了就别回头了 2020-12-03 20:58

I am trying to allow the user to customize the elements in a WPF application. What I am trying to achieve is, if I have a list box which specifies all the form elements (Tex

3条回答
  •  一生所求
    2020-12-03 21:27

    it worked for me like a charm:

    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;
    }
    

提交回复
热议问题