Harjeet Singh
Harjeet Singh

Reputation: 396

Add Resource to a ListBox in CodeBehind

I am working on a WPF Application, I have a requirement to add resources to a Listbox through code behind, because i am creating ListBox Dynamically. Below I have added the resources to listbox through XAML, how can I add the resources through CodeBehind?

  <ListBox.Resources>
   <SolidColorBrush  x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FFF3800C"  />
    <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}"  Color="#FFF3800C" />
    </ListBox.Resources>

Upvotes: 0

Views: 266

Answers (1)

Sivasubramanian
Sivasubramanian

Reputation: 965

Try whether this helps and let me know the results

SolidColorBrush highLightBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFF3800C"));
    this.listbox.Resources.Add("HighlightBrushKey", highLightBrush);

Upvotes: 1

Related Questions