1

I have a datagrid in which i manually specify the columns (AutoGenerateColumns="false"). I'm using MVVM and I would like to bind the column header (the text) so that I get it from my ViewModel. But I can't find a way to do that.

The closest thing I've found is this: Wpf Toolkit. Bind DataGrid Column Header to DynamicResource ...which is a "trick" with which you can bind the column header to a string statically declared in XAML. But I need to get it from my ViewModel.

The reason I want to this is that the text I want to use as column header will be shown in several places throughout the GUI. To get make sure it actually is the same everywhere I want to have it available in code. And I can't store the strings in a XAML resource file because I also need access to these strings in code.

I'm using a RadGridView from TeleRik, but I guessing I'd have the same problem if I the standard gridview.

Any tips appreciated! Thanks!

1 Answer 1

2

In Silverlight I have tried the following:

<DataGridTextColumn Header="{Binding ElementName=LayoutRoot, Path=DataContext.MyProperty}" ... />

(LayoutRoot is the first control in the Window/UserControl, MyProperty is something in the VM) It does not work because the column has no access to the visual tree.

It may be worth a try in WPF with your Grid.

Sign up to request clarification or add additional context in comments.

1 Comment

Did not work for me in WPF 4.5. Error "Framework mentor not found". I was using a DataGridTemplateColumn

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.