Kulpemovitz
Kulpemovitz

Reputation: 541

TreeView set Foreground and font

I Have a control I made using Winforms some years ago, I'm trying to rewrite it using WPF. I'm using a Treeview (unbound) Control as my base control, I need to change the foregroug color and font-size of some items depending on values I gather. I tried setting the foregroud using code :

    TreeViewItem n = new TreeViewItem();
    n.Header = item.Name;
    n.Tag = item;
    n.Foreground = new SolidColorBrush(Colors.LightGreen);

No luck. any help???

Upvotes: 1

Views: 4628

Answers (1)

brunnerh
brunnerh

Reputation: 184947

Well, what did you do with that item? If i create such an item and add it to a TreeView it does have a LightGreen text.

If you want to apply some coloring conditionally you might want to create a Style with Triggers which is applied to all TreeViewItems (set it as TreeView.ItemContainerStyle for example or add it to the TreeView.Resources with only a TargetType and not x:Key).

Upvotes: 1

Related Questions