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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:46:24+00:00 2026-06-06T23:46:24+00:00

I am creating a custom controltemplate for ListBox and I’m having difficulties with the

  • 0

I am creating a custom controltemplate for ListBox and I’m having difficulties with the visual states. When using the VisualState MouseOver, it affects all the items including the selected item, which I want to have separate styling.

In Metro, there is SelectedPointerOver, is there anything equivalent in WPF or other alternatives?

Edit:

For example, all items initially have black foreground.

When one item is selected, its foreground turns white (and non-selected items remain black foreground).

And now when I MouseOver the non-selected item, I will like its foreground to turn blue, and when I MouseOver the selected item, I will like its foreground to turn red.

  • 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-06T23:46:24+00:00Added an answer on June 6, 2026 at 11:46 pm

    To my knowledge there is no equivalent to that state in WPF.

    The WPF ListBoxItem has the states Unselected, Selected and SelectedUnfocused in group SelectionStates and the states Normal, MouseOver and Disabled in group CommonStates. States in each group are mutually exclusive, but states from different groups can be taken on simultaneously. The ListBoxItem can for example be in states Selected and MouseOver at the same time.

    It is up to the control template to define a visualization that takes this fact into account. It could for example fill the item with a different background brush when it is selected, and draw an outer border when the mouse is over the item. The important thing is that there are independent visualizations that are visible at the same time, as the related states are independent and can be taken on at the same time. A user would typically become a bit confused when a selected list item doesn’t look selected only because he moved the mouse over that item.

    EDIT – ListBox example below. Could perhaps be done a lot easier with Triggers instead of Visual States.

    <ListBox SelectionMode="Extended">
        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ListBoxItem">
                            <Grid Background="LightGray" Margin="1">
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Normal"/>
                                        <VisualState x:Name="Disabled"/>
                                        <VisualState x:Name="MouseOver">
                                            <Storyboard>
                                                <ColorAnimation Storyboard.TargetName="UnselectedText"
                                                                Storyboard.TargetProperty="Foreground.Color"
                                                                To="Blue" Duration="0:0:0.1"/>
                                                <ColorAnimation Storyboard.TargetName="SelectedText"
                                                                Storyboard.TargetProperty="Foreground.Color"
                                                                To="Red" Duration="0:0:0.1"/>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="SelectionStates">
                                        <VisualState x:Name="Unselected"/>
                                        <VisualState x:Name="Selected">
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetName="UnselectedText"
                                                                 Storyboard.TargetProperty="Opacity"
                                                                 To="0" Duration="0:0:0.1"/>
                                                <DoubleAnimation Storyboard.TargetName="SelectedText"
                                                                 Storyboard.TargetProperty="Opacity"
                                                                 To="1" Duration="0:0:0.1"/>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <TextBlock Name="UnselectedText" Margin="2" Text="{TemplateBinding Content}">
                                    <TextBlock.Foreground>
                                        <SolidColorBrush Color="Black"/>
                                    </TextBlock.Foreground>
                                </TextBlock>
                                <TextBlock Name="SelectedText" Margin="2" Text="{TemplateBinding Content}" Opacity="0">
                                    <TextBlock.Foreground>
                                        <SolidColorBrush Color="White"/>
                                    </TextBlock.Foreground>
                                </TextBlock>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ListBox.ItemContainerStyle>
        <ListBox.Items>
            <ListBoxItem Content="Item 1"/>
            <ListBoxItem Content="Item 2"/>
            <ListBoxItem Content="Item 3"/>
            <ListBoxItem Content="Item 4"/>
            <ListBoxItem Content="Item 5"/>
            <ListBoxItem Content="Item 6"/>
            <ListBoxItem Content="Item 7"/>
            <ListBoxItem Content="Item 8"/>
            <ListBoxItem Content="Item 9"/>
            <ListBoxItem Content="Item 10"/>
        </ListBox.Items>
    </ListBox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some problems creating custom types for my data table, using jquery.datatables.js.
I'm creating custom UserControl in ASP.NET and I'm using System.ComponentModel.Attributes to decorate properties with
I'm having problems creating custom forms in pyramid_formalchemy. I suspect there is a bug
I am using vs2010 and I am creating custom tfs2010 build template. So I
We are using a 3rd party HR Tool (NuView) and are creating custom reports
I am creating custom code snippet templates using DevExpress' CodeRush. Is there anyway for
I have a Rails blog using friendly_id for creating custom urls. The blog has
I am creating custom ViewGroup in which I am using onLayout method in which
Does anybody know of a method for creating custom Performance Counters using ordinary unmanaged
I'm creating a custom control called ImageFader. The style template looks like this: <ControlTemplate

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.