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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:33:32+00:00 2026-05-12T15:33:32+00:00

I have listbox with a TextBlock bound to a field, and the I have

  • 0

I have listbox with a TextBlock bound to a field, and the I have set the AlternationCount=”2″ this works great for changing the background color of the items control; however, I cannot get the effect I want with my rectangle… I’m trying to have a rounded corners effect on each listbox item.

edit: the xaml

<DataTemplate x:Key="TaskListTemplate">
    <Grid Height="276" Width="Auto">
        <Rectangle Fill="Gray" Stroke="Black" RadiusX="8" RadiusY="8" Margin="0"/>
        <TextBox x:Name="txtDescription" Text="{Binding Path=Des}" />
        <TextBox x:Name="txtComments" Text="{Binding Path=Com}"/>
        <Label Content="{Binding Path=Title}">
    </Grid>
</DataTemplate>

<ListBox Margin="8,37,0,6" 
    ItemContainerStyle="{DynamicResource ListBoxItemStyle}" 
    AlternationCount="2"
    ItemTemplate="{DynamicResource TaskListTemplate}"/>

<Style x:Key="ListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
        <Setter Property="FontSize" Value="12" />
        <Setter Property="FontFamily" Value="Tahoma" />
        <Setter Property="Background" Value="#006C3B3B"/>
        <Style.Resources>
          <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FF533F70"/>
          <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#FF533F70"/>
          <Storyboard x:Key="MouseOverStoryBoard">
            <ColorAnimationUsingKeyFrames AutoReverse="True" BeginTime="00:00:00" Storyboard.TargetName="{x:Null}" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00" Value="#FFF48F21"/>
                <SplineColorKeyFrame KeyTime="00:00:00.5000000" Value="#FF4A475C"/>
            </ColorAnimationUsingKeyFrames>
          </Storyboard>
        </Style.Resources>
        <Style.Triggers>
            <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                <Setter Property="Background">
                    <Setter.Value>
                        <SolidColorBrush Color="#FFA2BAD4"/>
                    </Setter.Value>
                </Setter>
                <Setter Property="Foreground" Value="White"/>
            </Trigger>
            <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                <Setter Property="Background" Value="#FF7395B9"/>
                <Setter Property="Foreground" Value="White"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Trigger.EnterActions>
                    <BeginStoryboard Storyboard="{StaticResource MouseOverStoryBoard}"/>
                </Trigger.EnterActions>
                <Setter Property="Foreground" Value="White" />
                <Setter Property="Background" Value="#FFF48F21"/>
                <Setter Property="FontStyle" Value="Normal"/>
            </Trigger>
        </Style.Triggers>
    </Style>
  • 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-12T15:33:33+00:00Added an answer on May 12, 2026 at 3:33 pm

    In my tests, changing the ItemTemplate (TaskListTemplate) did not have any effect.
    So the first step would be to do this in another way, I chose setting the ContentTemplate in the ListBoxItemStyle, which worked.
    Further, you want some rounded rectangle with an alternating background:
    I used a border for this in my modification of your code, but a rectangle would also work out similarly. Here I think, the key is to set the background of other elements transparent, otherwise they will hide your rectangle.
    Just copy the following code in Kaxaml to see what it looks like.

    <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <Page.Resources>
            <DataTemplate x:Key="TaskListTemplate">
                <Border MinWidth="50" Height="70" Background="{TemplateBinding ListBoxItem.Background}" BorderBrush="Black" CornerRadius="8" Margin="0">
                    <Grid Background="Transparent">
                        <TextBox x:Name="txtDescription" Text="{Binding Path=Des}" Background="Transparent"/>
                        <TextBox x:Name="txtComments" Text="{Binding Path=Com}" Background="Transparent"/>
                        <Label Content="{Binding Path=Title}" Background="Transparent"/>
                    </Grid>
                </Border>
            </DataTemplate>
            <Style x:Key="ListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
                <Setter Property="FontSize" Value="12"/>
                <Setter Property="FontFamily" Value="Tahoma"/>
                <Setter Property="Background" Value="#006C3B3B"/>
                <Setter Property="ContentTemplate" Value="{DynamicResource TaskListTemplate}"/>
                <Style.Resources>
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FF533F70"/>
                    <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#FF533F70"/>
                    <Storyboard x:Key="MouseOverStoryBoard">
                        <ColorAnimationUsingKeyFrames AutoReverse="True" BeginTime="00:00:00" Storyboard.TargetName="{x:Null}" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                            <SplineColorKeyFrame KeyTime="00:00:00" Value="#FFF48F21"/>
                            <SplineColorKeyFrame KeyTime="00:00:00.500" Value="#FF4A475C"/>
                        </ColorAnimationUsingKeyFrames>
                    </Storyboard>
                </Style.Resources>
                <Style.Triggers>
                    <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                        <Setter Property="Background">
                            <Setter.Value>
                                <SolidColorBrush Color="#FFA2BAD4"/>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="Foreground" Value="White"/>
                    </Trigger>
                    <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                        <Setter Property="Background" Value="#FF7395B9"/>
                        <Setter Property="Foreground" Value="White"/>
                    </Trigger>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Trigger.EnterActions>
                            <BeginStoryboard Storyboard="{StaticResource MouseOverStoryBoard}"/>
                        </Trigger.EnterActions>
                        <Setter Property="Foreground" Value="White"/>
                        <Setter Property="Background" Value="#FFF48F21"/>
                        <Setter Property="FontStyle" Value="Normal"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Page.Resources>
        <Grid>
            <ListBox Margin="8,37,0,6" 
                     ItemContainerStyle="{DynamicResource ListBoxItemStyle}" 
                     AlternationCount="2">
                <ListBoxItem>Test1</ListBoxItem>
                <ListBoxItem>Test2</ListBoxItem>
                <ListBoxItem>Test3</ListBoxItem>
            </ListBox>
        </Grid>
    </Page>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a listbox control with following DataTemplate <DataTemplate x:Key=lb_Itemtemplate> <DockPanel> <TextBlock Text={Binding}
i have this LongListSelector bound to observerableCollection <DataTemplate x:Key=ucItems > <Grid Margin=0,0,0,17> <TextBlock Text={Binding
I have Listbox which is bound to my view model. This view model has
I have one Listbox and applied one DataTemplate like this <ListBox> <ListBox.ItemTemplate> <Grid> <TextBlock
I have a data bound Listbox as shown below. I want the textblock that
I have a ListBox with an ItemTemplate consisting of a TextBlock and a ComboBox
I have a wpf listbox that implements a DataTemplate that contains a TextBlock. <local:BooleanToFontColorConverter
I have a ListBox with items that fill TextBox es. How do I identify
I have a ListBox whose ItemsSource is bound to a list of objects. The
I have a ListBox which is bound to a collection. When I add an

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.