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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:06:51+00:00 2026-06-17T21:06:51+00:00

I have a class with data: public class routedata : INotifyPropertyChanged { private List<double>

  • 0

I have a class with data:

public class routedata : INotifyPropertyChanged

{

    private List<double> distances;
    public List<double> Distances
    {
        get { return this.distances; }
        set
        {
            if (this.distances != value)
            {
                this.distances = value;
                this.onPropertyChanged("Distances");
            }
        }
    }

    private List<string> instructions;
    public List<string> Instructions
    {
        get { return this.instructions; }
        set
        {
            if (this.instructions != value)
            {
                this.instructions = value;
                this.onPropertyChanged("Instructions");
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void onPropertyChanged(string property)
    {
        if (this.PropertyChanged != null)
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(property));
        }
    }        
}

I’m trying to bind it to a listview like this:

     <GridView Name="routeView" HorizontalAlignment="Left" Height="310" Margin="1025,318,0,0" Grid.Row="1"      
           VerticalAlignment="Top" Width="340" >
            <ListView Name="routeList" Height="300" Width="330" ItemsSource="{Binding routeData}">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Instructions}"
                                                      TextWrapping="Wrap" Width="200"/>
                            <TextBlock Text="{Binding Distances}"
                                                      Margin="10,0,0,0" />
                            <TextBlock Text="km"/>
                        </StackPanel>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </GridView>

I have in my c# code behind: routeList.datacontext = this;

but it is still not binding, only one empty row is populated in the listview. I have checked the data and it is all present. Any help would be appreciated thank you.

  • 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-06-17T21:06:52+00:00Added an answer on June 17, 2026 at 9:06 pm

    A ListView takes a single collection as ItemsSource, so if you want to display multiple TextBlocks for each item – you need a collection of objects with multiple text properties to bind to your DataTemplate. In your case a routeData is not a collection. Instead you need to define your item view model, e.g.

    public class RoutePoint
    {
        public double Distance { get; set; }
        public string Instruction { get; set; }
    }
    

    then you would bind your ListView.ItemSource to a List and in your DataTemplate bind it like that:

    <TextBlock Text="{Binding Distance}"/>
    <TextBlock Text="{Binding Instruction}"/>
    

    You don’t need to use an ObservableCollection if your collection never changes after you bind it to the ListView for the first time (SelectedItem doesn’t constitute a change).

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

Sidebar

Related Questions

I have a List<Data> where: class Data { public string Name { get; set;
I have a list of this class: public class Data { public string name
I have list with items in my data class: public ObservableCollection<Node> NodesFromDatabase { get
I have the following Data class: class CustomerProducts { public string Id { get;
I have this class: public MyClass { public void initialize(Collection<String> data) { this.data =
I have the following code: Imports MySql.Data.MySqlClient Imports MySql.Data.Types Public Class FormMain Private Sub
Concerning data binding I have these classes: public class Foo : List<Bar> { public
I have a class like this: public class Data { public string Name {
I have some class. For example: public class Data { private String name; public
I have a class with several data members: public class Foo { List<int> intLst;

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.