Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Binding to an objects member variable in a List

Binding to an objects member variable in a List

Scheduled Pinned Locked Moved WPF
wpfhelpcsharpwcf
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xtr33me
    wrote on last edited by
    #1

    I am somewhat new to WPF and am loving the data binding, but it seems that I am still having a little bit of a rough time getting some things to work, one being this issue. I currently have an object that has a "Name" member variable as well as a few other member variables which I have made public accessors for. I then poulated a global List of these objects from a tab delimited file. I now have a listbox in my main window that I want to databind to the "Name" variable of each object listed in my List<> of these objects. In my XAML I currently have the below code where m_netObjArr is my global List which for each of my NetworkIDObjects I want to access their "Name" accessor.

    <ListBox Height="Auto" Name="lbNetSelect" Width="Auto" MouseRightButtonDown="lbNetSelect_MouseRightButtonDown"
    SelectionChanged="lbNetSelect_SelectionChanged" ItemsSource="{Binding ElementName=window1.m_netObjArr, Path=Name }"/>

    Any help or direction would be great! Thanks everyone!

    V 1 Reply Last reply
    0
    • X xtr33me

      I am somewhat new to WPF and am loving the data binding, but it seems that I am still having a little bit of a rough time getting some things to work, one being this issue. I currently have an object that has a "Name" member variable as well as a few other member variables which I have made public accessors for. I then poulated a global List of these objects from a tab delimited file. I now have a listbox in my main window that I want to databind to the "Name" variable of each object listed in my List<> of these objects. In my XAML I currently have the below code where m_netObjArr is my global List which for each of my NetworkIDObjects I want to access their "Name" accessor.

      <ListBox Height="Auto" Name="lbNetSelect" Width="Auto" MouseRightButtonDown="lbNetSelect_MouseRightButtonDown"
      SelectionChanged="lbNetSelect_SelectionChanged" ItemsSource="{Binding ElementName=window1.m_netObjArr, Path=Name }"/>

      Any help or direction would be great! Thanks everyone!

      V Offline
      V Offline
      Venkatesh Mookkan
      wrote on last edited by
      #2

      1. What is m_netObjArr? 2. If it is a member variable, then is it a public variable? Variable in a class has to bound like,

      {Binding ElementName=window1, Path=m_netObjArr.Name}

      or

      {Binding ElementName=window1, Source=m_netObjArr, Path=Name}

      Castle Rider


      My: Website | Yahoo Group | Blog Spot

      X B 2 Replies Last reply
      0
      • V Venkatesh Mookkan

        1. What is m_netObjArr? 2. If it is a member variable, then is it a public variable? Variable in a class has to bound like,

        {Binding ElementName=window1, Path=m_netObjArr.Name}

        or

        {Binding ElementName=window1, Source=m_netObjArr, Path=Name}

        Castle Rider


        My: Website | Yahoo Group | Blog Spot

        X Offline
        X Offline
        xtr33me
        wrote on last edited by
        #3

        m_netObjArr is my public global List<> of my NetworkIDObjects: m_netObjArr NetworkIDObjects is an object containing a number of variables that I populate from an XML file. I want to populate my Listbox with the "Name" variable value for each of the NetworkIDObjects in my List and I do have a public accessor for Name. Thanks for your time!

        1 Reply Last reply
        0
        • V Venkatesh Mookkan

          1. What is m_netObjArr? 2. If it is a member variable, then is it a public variable? Variable in a class has to bound like,

          {Binding ElementName=window1, Path=m_netObjArr.Name}

          or

          {Binding ElementName=window1, Source=m_netObjArr, Path=Name}

          Castle Rider


          My: Website | Yahoo Group | Blog Spot

          B Offline
          B Offline
          BechBej
          wrote on last edited by
          #4

          You can bind the list box to the collection and set the display member path property to the property name wich is name in this case and you will have all names displayed in the list

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups