MaterialDesignInXAML / MaterialDesignInXamlToolkit

Google's Material Design in XAML & WPF, for C# & VB.Net.
http://materialdesigninxaml.net
MIT License
15.18k stars 3.43k forks source link

Cannot dynamically change the background color of the TreeViewItem during drag drop TreeViewItem #2135

Closed 42805578 closed 4 years ago

42805578 commented 4 years ago

When drag drop a TreeViewItem over another TreeViewItem, I want to change the background color of the target TreeViewItem, in my c# code, I set the background as below: targetTreeViewItem.Background=Colors.Green; but the background not change

Any advice?

stigrune commented 4 years ago

The background is set to transparent with no possible overrides in the default templates.

This is a custom case and you can solve it by implementing your own custom TreeViewItem template that is used in your application. Base it of MaterialDesignTreeViewItem in MaterialDesignTheme.TreeView.xaml and modify to your linking. It’s not 100% clear on what your need is, but I’m guessing you’re interested in changing the background color on the header at line 279.

Another possible solution for you would be use WPF adorners to achieve a similar effect on dragover.

Keboo commented 4 years ago

This looks like a simple thing that could be fixed. Simply replacing the hard coded value (as indicated by @stigrune) with a TemplateBinding should fix it (ideally adding a corresponding UI test).