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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:14:36+00:00 2026-05-27T01:14:36+00:00

I have a ListBox which is bound to my custom class ObservableCollection<FieldPropertyItem> _fieldOrderCollection`; internal

  • 0

I have a ListBox which is bound to my custom class

ObservableCollection<FieldPropertyItem> _fieldOrderCollection`;
internal struct FieldPropertyItem
{
  public string Name { get; set; }
  public string AliasName { get; set; }
}

Code for ListBox:

<ListBox x:Name="FieldOrderListBox" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" 
         VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" SelectedIndex="0"
         ScrollViewer.VerticalScrollBarVisibility="Auto" SelectionChanged="FieldOrderListBox_SelectionChanged">
    <ListBox.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#FF479EF3"></SolidColorBrush>
    </ListBox.Resources>

       <ListBox.ItemTemplate>
        <DataTemplate x:Name="MyTemplate">
            <Grid  Margin="-5,-1,0,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" SharedSizeGroup="FieldName" MinWidth="5" MaxWidth="300"/>
                    <ColumnDefinition Width="2" />
                    <ColumnDefinition Width="*" MaxWidth="350"/>
                </Grid.ColumnDefinitions>                                

                <Border  BorderBrush="Black" Grid.Column="0" BorderThickness="0.5,0.0,0.5,0.5" IsHitTestVisible="False">
                    <TextBlock Text="{Binding Name}" Grid.Column="0" ToolTip="{Binding Name}" Margin="2,0,2,0" VerticalAlignment="Center"/>
                </Border>
                <GridSplitter Grid.Column="1" Width="2" HorizontalAlignment="Left" Background="Black" Margin="-2,0,-1,0"/>
                <Border BorderBrush="Black" BorderThickness="0,0.0,0.5,0.5" Margin="-2,0,0,0" Padding="0,5,0,0" Grid.Column="2">
                    <TextBlock Text="{Binding AliasName}" Grid.Column="1" ToolTip="{Binding AliasName}" Margin="2,0,2,0" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
                </Border>
            </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

Now i want that my ListBox first item should look like header. The remaining ones should have a light dim background.

  • 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-27T01:14:36+00:00Added an answer on May 27, 2026 at 1:14 am

    You can check if the previous item is null using a RelativeSource binding in a trigger, e.g. this DataTemplate makes the first element bold:

    <DataTemplate>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition SharedSizeGroup="A" />
                <ColumnDefinition SharedSizeGroup="B" />
            </Grid.ColumnDefinitions>
            <Grid.Style>
                <Style TargetType="{x:Type Grid}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource PreviousData}}" Value="{x:Null}">
                            <Setter Property="TextElement.FontWeight" Value="Bold" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Grid.Style>
            <TextBlock Grid.Column="0" Text="{Binding Name}" />
            <TextBlock Grid.Column="1" Text="{Binding AliasName}" />
        </Grid>
    </DataTemplate>
    

    (Use shared size groups as shown above to align the grids with one-another, set Grid.IsSharedSizeGroup to true on the ListBox element)

    I would not recommend doing this by the way, if your item collection contains the header there is definitely something wrong with your data-design.

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

Sidebar

Related Questions

I have a ListBox which is bound to ObservableCollection of LogMessages. public ObservableCollection<LogMessage> LogMessages
I have two classes: public class Person { public string FirstName { get {
I have this ListBox which is bound to an ObservableCollection. Each object in the
I have WPF ListBox which is bound to a ObservableCollection, when the collection changes,
I have a WPF ObservableCollection which is bound to a ListBox and I have
I have a Silverlight Listbox bound to Observablecollection which shows up fine (first time)
I have a listbox which is bound to a CollectionViewSource (backed by an ObservableCollection).
So, I have a ListBox which is bound to a list of business objects,
I have a standard Listbox which is bound to a property in my viewmodel
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.