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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:44:56+00:00 2026-06-06T22:44:56+00:00

I have this style: <Style x:Key=SelectableListBoxItemStyle TargetType={x:Type ListBoxItem}> <Setter Property=Template> <Setter.Value> <ControlTemplate TargetType={x:Type ListBoxItem}>

  • 0

I have this style:

<Style x:Key="SelectableListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ListBoxItem}">

                <Border Background="Transparent"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        CornerRadius="4"
                        BorderThickness="2"
                        x:Name="IconBorder"
                        Margin="4,2,4,2">
                    <ContentPresenter/>
                </Border>

                <ControlTemplate.Triggers>
                    <Trigger Property="IsSelected" Value="true">
                        <Setter TargetName="IconBorder" 
                                Property="BorderBrush" 
                                Value="Blue" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

My problem is that I don’t know which property to set on the ListBox, when consuming my style so that the borders of it’s ListBoxItems would end up having the desired border brush. I would also like to make this work for the other border brush in my style.

I would like to be able to have two list boxes with this same style but different border colors. I have this for a ListBox:

    <ListBox 
        ItemsSource="{Binding SelectedProduct.Pictures}"
        SelectedItem="{Binding SelectedSet, Mode=TwoWay}"
        ItemContainerStyle="{StaticResource ResourceKey= SelectableListBoxItemStyle}">
    </ListBox>

Update..I tried this:

    <ListBox 
        ItemsSource="{Binding SelectedProduct.Pictures}"
        SelectedItem="{Binding SelectedSet, Mode=TwoWay}">

            <ListBox.ItemContainerStyle>
                <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource SelectableListBoxItemStyle}">
                    <Setter TargetName="IconBorder" Property="BorderBrush" Value="Green" />
                </Style>
            </ListBox.ItemContainerStyle>

        </ListBox>

But, I get:
Error 8 TargetName property cannot be set on a Style Setter.

  • 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-06T22:44:57+00:00Added an answer on June 6, 2026 at 10:44 pm

    Instead of using a TemplateBinding you should try using a relative source binding.

    BorderBrush="{Binding RelativeSource={RelativeSource FindAncestor, 
                                          AncestorType={x:Type Listbox}}, 
                                          Path=BorderBrush}"
    

    If you want to have a different border than that defined for the ListBox then you will need to add a brush resource to your ResourceDictionary and apply that instead:

    <Listbox.Resources>
        <SolidColorBrush x:Key="MyListBoxItemBorderBrush" Color="Red"/>
    <Listbox.Resources>
    

    and then in your template:

    BorderBrush="{StaticResource MyListBoxItemBorderBrush}"
    

    If you need certain items to have different borders then you need to look at a StyleSelector.

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

Sidebar

Related Questions

So I have this WPF style: <Style x:Key=SmallLinkButton TargetType=Button> <Setter Property=Template> <Setter.Value> <ControlTemplate TargetType=Button>
hi everyone i have a xaml code like this <Style x:Key = {x:Type TabItem}
I have this CSS style that does a rounded corners for div border, but
I have this in my CSS file: body {style.css (line 3) background:#CDF8FF url(images/final_bg.jpg) no-repeat
I have this: <ul class=deposit style=float:left;list-style-type:none;> <a href=javascript:void(0) id=inc><li class=first>+</li></a> <a href=javascript:void(0) id=dec><li class=second>-</li></a>
I have this string text: <meta http-equiv=Content-Type content=text/html; charset=utf-8> <style type=text/css> body { font-family:
I have this app (contacts style) in which you can add instances to a
I have this function, that adds 31px to my style bottom on ul. It
I have this in res/values/styles.xml <style name=ListViewRowBorder > <item name=android:width>1dp</item> <item name=android:color>@color/listview_row_stroke_color</item> </style> I
I have this piece of HTML code: <tr class=AttCardFooter onMouseOver=this.style.backgroundColor='#E1EAFE' onMouseOut=this.style.backgroundColor='Transparent'>...etc etc.. new lines

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.