I do as here http://www.sql.ru/forum/929430/wpf-c-peredacha-cveta-iz-metoda-i-ispolzovanie-ego-dlya-fona-animaciya

After starting the program, the color of the Background TreeViewItem does not change.

<TreeView> <TreeView.ItemContainerStyle> <Style TargetType="{x:Type TreeViewItem}"> <Style.Triggers> <Trigger Property="IsSelected" Value="False" > <Setter Property="Background" Value="{Binding collection_node, ConverterParameter=color_text,Converter={StaticResource ConverterColor}}"></Setter> public class ConverterColor : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { try { return Brushes.Red; } catch { return null; } } 

But if you replace it with that, the color changes: <Setter Property="Background" Value="#FF0000"></Setter>

  • And it works like this: <Trigger Property="IsSelected" Value="False"><Setter Property="Background" Value="Red"/></Trigger> ? - VladD
  • So it works ... - codename0082016
  • one
    Ok, so the problem is with Binding. Do you have a converter? Set breakpoint to Convert . - VladD
  • Called. At the exit of it return Brushes.Orange; "{Name = Orange, ARGB = (255, 255, 165, 0)}" - codename0082016
  • one
    worked with return Brushes.Red; There is an obvious problem with Binding. But I tried to do a binding like {Binding RelativeSource = {RelativeSource Self}, ConverterParameter = color_text, Converter = {StaticResource ConverterColor}} - user2455111

1 answer 1

 public class ConverterColor : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { ... return "#00ff00"; ... } } {Binding RelativeSource={RelativeSource Self}, ConverterParameter=color_text,Converter={StaticResource ConverterColor}}