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

  • Home
  • SEARCH
  • 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 523571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:28:34+00:00 2026-05-13T08:28:34+00:00

i have a ListView which contains objects bound from an collection. The representation of

  • 0

i have a ListView which contains objects bound from an collection. The representation of the objects I have set with a DataTemplate. Now I want to do the following.
There are two TextBlocks in my DataTemplate:

<DataTemplate>
   <StackPanel>
       <TextBlock Text="{Binding Name}"></TextBlock>
       <TextBlock Text="{Binding Path}"></TextBlock>
   </StackPanel>
</DataTemplate>

I already have specified an ItemContainerStyle which I use to realize a hover-effect.

<Style TargetType="ListViewItem" x:Key="ContainerStyle">
       <Style.Triggers>
                 <EventTrigger RoutedEvent="Mouse.MouseEnter">
  ... and so on

My aim is to underline the TextBlock which contains the Name, when user moves mouse over the ListViewItem. The Path shouldn’t be underlined. How can this be realized? How can an element in DataTemplate can be accessed for each ListViewItem?

Greetings,
Martin

  • 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-13T08:28:35+00:00Added an answer on May 13, 2026 at 8:28 am

    You can do this either by specifying the ControlTemplate for the ListViewItem, or by changing the DataTemplate. The example below shows both methods. Note that you lose the blue background for the selected ListViewItem when you use the ControlTemplate (when you comment it out it returns)
    EDIT:
    I did not read your requirement well. You only want to underline the Name. Then the only possibility is to use the Datatemplate, or to rewrite the ControlTemplate of the TextBox.

    <Window x:Class="Underlining.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300"
       >
        <StackPanel>
            <ListView ItemsSource="{Binding}">
                <ListView.ItemContainerStyle>
                    <Style TargetType="ListViewItem">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ListViewItem">
                                    <Border Name="UnderlineInControlTemplate" BorderThickness="2,0,2,0"
                                            BorderBrush="Transparent">
                                        <ContentPresenter HorizontalAlignment="Left"
                                                          VerticalAlignment="Center"/>
                                    </Border>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsMouseOver" Value="True">
                                            <Setter TargetName="UnderlineInControlTemplate"
                                                    Property="BorderBrush"
                                                    Value="BlueViolet"/>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListView.ItemContainerStyle>
                <ListView.ItemTemplate>
                    <DataTemplate>
                    <StackPanel>
                        <Border Name="UnderlineInDataTemplate" BorderThickness="0,0,0,2"
                            BorderBrush="Transparent">
                             <TextBlock Text="{Binding Name}"/>
                        </Border>
                        <TextBlock Text="{Binding Path}"/>
                    </StackPanel>
                        <DataTemplate.Triggers>
                            <Trigger Property="TextBlock.IsMouseOver" Value="True">
                                <Setter TargetName="UnderlineInDataTemplate"
                                        Property="BorderBrush"
                                        Value="Red"/>
                            </Trigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </StackPanel>
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 279k
  • Answers 279k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Because Map is already generified - your job when creating… May 13, 2026 at 3:25 pm
  • Editorial Team
    Editorial Team added an answer Using the html helper is both resource expensive and helpless:… May 13, 2026 at 3:25 pm
  • Editorial Team
    Editorial Team added an answer You can wrap a native type into a struct (quick… May 13, 2026 at 3:25 pm

Related Questions

Within an event, I'd like to put the focus on a specific TextBox within
I created an ArrayList which contains KeyValuePair<string, string> objects. There are ListBoxes which I
I have an Android app with a ListActivity in the main view. The list
I am breaking my head to fix an issue. I have a method that
Couldn't find an answer to this one. I have a WPF ListView control that

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.