Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 736383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:35:55+00:00 2026-05-14T07:35:55+00:00

I have the following problem. The background color in a ListView is set LightGreen

  • 0

I have the following problem.

The background color in a ListView is set LightGreen or White, whether a boolflag is true or false.

Example Screen

Window1.xaml:

<Window.Resources>

    <Style TargetType="{x:Type ListViewItem}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=BoolFlag}" Value="True">
                <Setter Property="Background" Value="LightGreen" />
            </DataTrigger>
        </Style.Triggers>
    </Style>

</Window.Resources>

<StackPanel>
    <ListView ItemsSource="{Binding Path=Personen}" SelectionMode="Single" SelectionChanged="ListViewSelectionChanged">
        <ListView.View>
            <GridView>
                <GridViewColumn DisplayMemberBinding="{Binding Path=Vorname}" Header="Vorname" />
                <GridViewColumn DisplayMemberBinding="{Binding Path=Nachname}" Header="Nachname" />
                <GridViewColumn DisplayMemberBinding="{Binding Path=Alter}" Header="Alter" />
                <GridViewColumn DisplayMemberBinding="{Binding Path=BoolFlag}" Header="BoolFlag" />
            </GridView>
        </ListView.View>
    </ListView>
</StackPanel>

Window1.xaml.cs:

public partial class Window1 : Window
{
    private IList<Person> _personen = new List<Person>();

    public Window1()
    {
        _personen.Add(new Person 
                {
                    Vorname = "Max",
                    Nachname = "Mustermann",
                    Alter = 18,
                    BoolFlag = false,
                });

        _personen.Add(new Person 
                {
                    Vorname = "Karl",
                    Nachname = "Mayer",
                    Alter = 27,
                    BoolFlag = true,
                });

        _personen.Add(new Person 
                {
                    Vorname = "Josef",
                    Nachname = "Huber",
                    Alter = 38,
                    BoolFlag = false,
                });

        DataContext = this;

        InitializeComponent();
    }

    public IList<Person> Personen
    {
        get
        {
            return _personen;
        }
    }

    private void ListViewSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        Person person = e.AddedItems[0] as Person;

        if (person != null)
        {
            if (person.BoolFlag)
            {
                this.Resources[SystemColors.HighlightBrushKey] = Brushes.Green;
            }
            else
            {
                this.Resources[SystemColors.HighlightBrushKey] = Brushes.RoyalBlue;
            }
        }
    }
}

Person.cs:

public class Person
{
    public string Vorname { get; set; }

    public string Nachname { get; set; }

    public int Alter { get; set; }

    public bool BoolFlag { get; set; }
}

Now I want to set the highlight color of the selected item, depending on the boolflag.
In Code-Behind I do this with:

private void ListViewSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        Person person = e.AddedItems[0] as Person;

        if (person != null)
        {
            if (person.BoolFlag)
            {
                this.Resources[SystemColors.HighlightBrushKey] = Brushes.Green;
            }
            else
            {
                this.Resources[SystemColors.HighlightBrushKey] = Brushes.RoyalBlue;
            }
        }
    }
}

This works fine, but now I want to define the code above in the XAML-file.

With

<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Green" />

I can overwrite the default-value. However, it works, but the color is set to Green for all selected items. I have tried different ways to switch the color of HighlightBrushKey between Green and Blue in XAML, depending on the boolflag, but I didn’t succeed.

May you can help me and give me some examples?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:35:56+00:00Added an answer on May 14, 2026 at 7:35 am

    Don’t know why highlightBrushKey is not so flexible. For a similar reason i switched on to an alternative way of setting the selected items background color by making using of its border. You can take a look at this http://vbcity.com/blogs/xtab/archive/2009/06/28/background-color-for-wpf-listbox-selected-item.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following textview in my Activity. I want to change the background color
I have the following CSS: .top-category-item { height: 338px; background-color: black; position: relative; }
i got the following problem. i have a ListView with custom rows consisting of
Hi I have the following problem: When using all browser, it showing background OK.
I have the following code <HTML> <HEAD> <style type=text/css> .setbgcolor{ background-color:blue; } </style> <script
I have following problem: I have to make a ASP.NET Webapplication with a two-row
I have following problem: I have built a tabbar application with 4 tabs. I
I have following problem, Code: String a=Yeahh, I have no a idea what's happening
Hi i have following Problem. I write a Mediawiki Extension where i need some
I am using GWT/JAVA for development. I have following problem: I want to remove

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.