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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:17:06+00:00 2026-05-28T15:17:06+00:00

If I am styling a list box, sometimes I’ll have a divider between each

  • 0

If I am styling a list box, sometimes I’ll have a divider between each element. BUT I don’t want that divider below the final element.

the problem

Is there some sort of converter trickery I can use to get this? (Silverlight 5)

Answer thanks to the below post:

XAML:

<UserControl
    x:Class="SilverlightApplication41.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:SilverlightApplication41"
    Width="640" Height="480">

    <UserControl.Resources>
        <local:NotLastItemToVisibilityConverter x:Key="NotLastItemToVisibilityConverter"/>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="White">
        <Border Background="#EEEDED" HorizontalAlignment="Left" VerticalAlignment="Center">
            <ListBox x:Name="_listbox" Background="#FFEEEDED" BorderBrush="#FF585858">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="2">
                            <TextBlock Text="{Binding}"/>
                            <Rectangle Fill="Orange" Height="2" VerticalAlignment="Bottom" Margin="1,0,1,-2"
                                       Visibility="{Binding Converter={StaticResource NotLastItemToVisibilityConverter}}"/>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Border>
    </Grid>
</UserControl>

CS:

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Collections.Generic;

namespace SilverlightApplication41
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            // Required to initialize variables
            InitializeComponent();
            List<string> dataList = new List<string>(){"Ants", "Bats", "Cats", "Dogs", "Entoloma sinuatum"};
            ((NotLastItemToVisibilityConverter)Resources["NotLastItemToVisibilityConverter"]).DataList = dataList;
            _listbox.ItemsSource = dataList;
        }

    }

    public class NotLastItemToVisibilityConverter : IValueConverter
    {
        public List<string> DataList {get; set;}

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if(DataList.Count == 0 || (string)value == DataList[DataList.Count-1])
            {
                return Visibility.Collapsed;
            }
            return Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}

Note: The comparison needs to be an object comparison OR unique strings in the list. Otherwise the list A,B,A would only have a divider after B since “A” == “A”. So this is a bad example using a string but makes the point. I tried casting DataList[DataList.Count-1] to an object but it doesn’t seem that the binding uses the exact string passed in.

  • 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-28T15:17:07+00:00Added an answer on May 28, 2026 at 3:17 pm

    Yes there will be some converter trickery.

    Bind the visibility of the divider to the list item. Then in the converter check return true if it’s not the .Last() item in the list and false if it is. You will need to get access to the view model in the converter.

    I don’t have the code to hand right now, but I’ve done something similar to this to enable/disable buttons.

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

Sidebar

Related Questions

I have an ordered list in HTML. I would like to add styling only
I'm having trouble styling a select list in an html form. Basically I want
i am styling a navigation menu using the following css. I have found that
Should the list styling properties go on the ul element or the li elements?
I have a style for styling <a> elements in list items in a #navigation
i have a list of objects that once a user clicks on i would
I have an ASP.NET application with contains a list of hyperlinks. After each hyperlink,
I have a dropdown list in my C# / .NET project that is on
I'm trying to style a definition list such that each dt floats to the
Who thought that styling a list of links could be so troublesome! First issue

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.