WPF reusing the same template across multiple columns
The following question https://social.msdn.microsoft.com/Forums/silverlight/en-US/f84e0efd-b1f2-4ab6-9af7-41fa95b5315d/how-to-set-data-binding-for-a-shared-datatemplate?forum=wpf basically exactly describes my problem. I need some new takes on this.
DataTemplateSelector
might work. The example at https://github.com/microsoft/WPF-Samples/blob/master/Data%20Binding/DataTemplatingIntro/TaskListDataTemplateSelector.cs is just extremely bad code. (really, looking up the resource in the current main window? it should be looked up next to the element.) Maybe both the example and the docs are just so jank that I didn't understand it correctly at all.
I've actually just tried using it, it creates nothing, I'm totally blank on why. https://github.com/AntonC9018/uni_gui/blob/bb16f5a4007eb78bec98df28e51cbc14f2cb59d1/lab1/TemplateSelector.cs
https://github.com/AntonC9018/uni_gui/blob/bb16f5a4007eb78bec98df28e51cbc14f2cb59d1/lab1/Form1.xaml#L40-L76
The question rephrased: how do I share a single template that's in resources across multiple columns of a data grid, with databinding support, that is, I want to be able to specify, at the data column level, to which property the control in the instantiated template should bind, without copy-pasting the template definition in each of the columns?0 Replies