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 8717837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:23:15+00:00 2026-06-13T06:23:15+00:00

I programmatically fill my listview with Strings using a foreach statement without using .itemssource

  • 0

I programmatically fill my listview with Strings using a foreach statement without using .itemssource and then i created this style trigger (which appears to be correct)

<ListView.Resources>
            <Style TargetType="ListViewItem">
                <Setter Property="IsSelected" Value="True" />
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Background" Value="Green"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
</ListView.Resources>

And then i run the project and click on a list view item… and the background is blue ……..

I’m Just wondering if style triggers require the use of databinding… or if my trigger is wrong.. or if anyone has any ideas.. ???

  • 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-06-13T06:23:15+00:00Added an answer on June 13, 2026 at 6:23 am

    Your problem is not related to binding, and the Trigger is also OK, except that it will be ineffective.

    The background color of a selected ListViewItem is set by the VisualStateManager in the ListViewItem’s ControlTemplate like show in the MSDN example:

    <Style TargetType="ListViewItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Border x:Name="Border" Background="Transparent" ...>
                        <VisualStateManager.VisualStateGroups>
                            ...
                            <VisualStateGroup x:Name="SelectionStates">
                                <VisualState x:Name="Unselected" />
                                <VisualState x:Name="Selected">
                                    <Storyboard>
                                        <ColorAnimationUsingKeyFrames
                                            Storyboard.TargetName="Border"
                                            Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                                            <EasingColorKeyFrame KeyTime="0"
                                                Value="{StaticResource SelectedBackgroundColor}" />
                                        </ColorAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                ...
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    

    No matter to what value you set the item’s background, it will be set to the value of {StaticResource SelectedBackgroundColor} when the item’s state is Selected. You might however add the following lines to your ListViewItem style to override the value of the SelectedBackgroundColor resource:

    <Style TargetType="ListViewItem">
        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Green" />
        </Style.Resources>
        ...
    </Style>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView (in WPF app) which I fill it programmatically: l1.Items.Add(new {
In our document generation system we use DOCX files in which we programmatically fill
Using C# and ASP.NET I want to programmatically fill in some values (4 text
I am using the Frame navigation control. Programmatically, I specify the page to fill
I want to programmatically fill in some fields in a form in PDF format.
How do you set the width of a textbox to fill the container programmatically?
I want to fill several UILabels, on different UIViews created with IB, with the
I have HTML template which has empty forms. How can i fill these forms
I am trying to make this ViewGroup programmatically, but I am having trouble doing
I am using in my app in SqlDataSource to fill a dropdownlist ,i configure

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.