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. Bind the Text property of a TextBlock inside a ListView inside a cell of a DataGrid to a ViewModel

Bind the Text property of a TextBlock inside a ListView inside a cell of a DataGrid to a ViewModel

Scheduled Pinned Locked Moved WPF
wpfcsharptutorialquestionvisual-studio
2 Posts 2 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.
  • M Offline
    M Offline
    Mc_Topaz
    wrote on last edited by
    #1

    The subject really say it all, even if it sounds over-complicated. Please hang on. I have a DataGrid. There are several columns in the DataGrid. One of the columns contains a ListView. The listView holds several rows. Each row contains a TextBlock and a Button. The TextBlock's Text property contains a name, which I want to pass to my ViewModel. I have managed to create a small example of this which should be just to "copy-paste-run". Since it is "a lot" of code I have made a public gist to store it in. Link to source in GIT Gist[^] Setup: * I use Visual Studio 2015 and compiling to NET 4.5.2. * I also use Fody.PropertyChanged, then I'm not needed to manually type all stuff required for the INotifyPropertyChanged interface. * Create a new WPF application and call it: WpfTest. * Save the project. * Install the Fody.Propertychanged in the NuGet Package Manager. * Create the FodyWeavers.xml file. * Paste all code from the Gist. Note: If the compiler says: "Fody: Could not find a weaver named 'PropertyChanged'. ..." Remove the from the FodyWeaver.xml file and try again. That line is not neccessary for this and I don't understand why it sometimes fail when compiling. This is what I want If you click any of the buttons in the DataGrid I want the associated name on the same row in the ListView to be bound to the SelectedName property in the ViewModel. I have no clue how to do the binding of the selected Textblock's Text property to the ViewModel in the View's xaml code. For example: Press the button to the right of NameA. I then want my ViewModels SelectedName to be "NameA". I tried this in the ListView, but no luck:

    I also tried this, with no luck:

    Please, how can I do this? P.S I can kinda get this to work by binding the SelectedItem property from the DataGrid and the SelectedIndex property from the ListVie

    L 1 Reply Last reply
    0
    • M Mc_Topaz

      The subject really say it all, even if it sounds over-complicated. Please hang on. I have a DataGrid. There are several columns in the DataGrid. One of the columns contains a ListView. The listView holds several rows. Each row contains a TextBlock and a Button. The TextBlock's Text property contains a name, which I want to pass to my ViewModel. I have managed to create a small example of this which should be just to "copy-paste-run". Since it is "a lot" of code I have made a public gist to store it in. Link to source in GIT Gist[^] Setup: * I use Visual Studio 2015 and compiling to NET 4.5.2. * I also use Fody.PropertyChanged, then I'm not needed to manually type all stuff required for the INotifyPropertyChanged interface. * Create a new WPF application and call it: WpfTest. * Save the project. * Install the Fody.Propertychanged in the NuGet Package Manager. * Create the FodyWeavers.xml file. * Paste all code from the Gist. Note: If the compiler says: "Fody: Could not find a weaver named 'PropertyChanged'. ..." Remove the from the FodyWeaver.xml file and try again. That line is not neccessary for this and I don't understand why it sometimes fail when compiling. This is what I want If you click any of the buttons in the DataGrid I want the associated name on the same row in the ListView to be bound to the SelectedName property in the ViewModel. I have no clue how to do the binding of the selected Textblock's Text property to the ViewModel in the View's xaml code. For example: Press the button to the right of NameA. I then want my ViewModels SelectedName to be "NameA". I tried this in the ListView, but no luck:

      I also tried this, with no luck:

      Please, how can I do this? P.S I can kinda get this to work by binding the SelectedItem property from the DataGrid and the SelectedIndex property from the ListVie

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      No sympathy. 1. Add a click handler / delegate that "stuffs" the "selection"; i.e. "code behind". (It's PLUMBING). 2. And you don't need all that "property changed stuff". If you know you are refreshing all controls on a container, you can call propertychanged with "no name" (on the container) and refresh all with one statement. You need a really "slow" machine for individual "property changed" events to make a difference.

      "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

      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