C# WPF how to sort listbox alphabetically

I have a C# WPF list box, lstMaintTechs that I have been trying to sort alphabetically.  I'm new to C# and WPF and just can't seem to make it happen.  Here is my code:

public List<tblMaintTech> Tech { get; set; }

        private void bindlistbox()  //called when window is initiallized
            
        {
            ProdTrackEntities pte = new ProdTrackEntities();
            Tech = pte.tblMaintTechs.ToList();
            DataContext = Tech;
        }

Open in new window


And here is the XAML for the listbox:
<ListBox x:Name="lstMaintTech" ItemsSource ="{Binding}" SelectedValuePath="MaintTechName" DisplayMemberPath="MaintTechName" HorizontalAlignment="Left" Margin="42,17,0,0" VerticalAlignment="Top" Width="203" FontSize="20" Height="465" IsSynchronizedWithCurrentItem="False" SelectionChanged="lstMaintTech_SelectionChanged" />

Open in new window


Any help would be great.  Thanks in advance!
Jeff HeilmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dustin SaundersDirector of OperationsCommented:
You can order it with LINQ:

Say I want to sort by the entity property 'FirstName'

Tech = pte.tblMaintTechs.OrderBy(mt => mt.FirstName).ToList();

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jeff HeilmanAuthor Commented:
I knew it had to be simple.  All of the examples I found had a ton of code to do something that should be easy.  Thanks a million Dustin!  Have a great day.
0
Dustin SaundersDirector of OperationsCommented:
Not a problem, good luck!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WPF

From novice to tech pro — start learning today.