C# WPF Tips : How to bind array/list elements

Binding is an ideal technique for displaying dybanic content in to application in WPF. Todays tips is about how to bind list/array elements in a C# WPF app.

In my C# code I have specified the binding as follows.

 List<string> myvalues = new List<string>() { "May 2020", "May", "Monday", "25/May/2020" };

I wan t to bind the second element, that means second element in the list (1th). So lets udjust the xaml bining

 <TextBlock  FontSize="14"   x:Name="txt_month" Text="{Binding [1]}" Foreground="Bisque"/>

We have used ‘[ ]’ to specify the element. If you have array of object you can use [ ] .<member> to specify the public member of the class too.

Published by


A developer,teacher and a blogger obsessed with Python,Dart and open source world from India

2 thoughts on “C# WPF Tips : How to bind array/list elements”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.