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