WPF binding problem in datagrid header
Hi, so I have set up a viewmodel and a view. The viewmodel is referenced inside the view's XAML as Page.DataContext. The viewmodel has INotifyPropertyChanged implemented and the necessary properties are public and have a getter and are set to a string value. Now when I am binding the value to the Header property of the datagrid column ("DataGridTextColumn"), it does not show up. However the property "Binding" where a property of the viewmodel's list of persons is bound, it works perfectly. By debugging I found this message: Severity Count "Cannot find governing FrameworkElement or FrameworkContentElement for target element." Data Context: null
I have already tried setting the DataContext via the relative source, changing merely anything i could think of, but im stumped. Please help me



13 Replies
This is .NET 8.0 and VS2022

you dont need this
ObservableCollection already does it by default
u can just
u also dont need to do

you are already initializing it to something
as for the header I am unsure maybe its trying to find it from the Persons collection
try doing DataContext.IsMarriedHeader
I will check in a minute just go home
@yambo mind $paste to the link below your vm and xaml so I dont have to rewrite it
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
BlazeBin - zlbimdiolink
A tool for sharing your source code with the world!
BlazeBin - jmqkiyavdcfe
A tool for sharing your source code with the world!
Thank you!
yeah this was just one of my desperate attempts :D
yeah this doesnt work for me sadly, i already tried a lot of combinations
and thx for the pastes I will take a look in a few
its a bit more complex than I expected because it doesn't let u relative from the Header apparently...

goddamn
thank you so much
may i ask you what your thought process was behind fixing this? i swear i tried out so much with relativesource binding
I just looked into the source saw it had a template and tried to bind to it since it couldn't reference a path or source from the Binding
that would let me use an outer context