I would think that this would be incredibly simple, but I’ve searched all over and can’t seem to find an answer. I have a DataGridTemplateColumn that I want to use to display a value that isn’t in the DataContext of the DataGrid. I.e. I have an entity that has different names based on the culture. When the grid loads, I want to go get the appropriate name based on the current culture. Every time I see anything about DataGridTemplateColumns, they’re always using the Binding syntax. I can’t do that here. What C# code do I need to access the “nameValue” TextBlock in the following XAML, and in what event handler should I access it:
<Datagrid:DataGridTemplateColumn Header="Name" x:Name="nameField">
<Datagrid:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<TextBlock x:Name="nameValue" />
</StackPanel>
</DataTemplate>
</Datagrid:DataGridTemplateColumn.CellTemplate>
</Datagrid:DataGridTemplateColumn>
Thanks to all in advance and I’m sorry for the super n00b question.
You can still use the binding syntax, it sounds like you just need to bind to a static method instead of the data context of the grid. There is a good reference here http://blog.mrlacey.co.uk/2011/03/binding-to-static-classes-in-windows.html Taking that as an example and modifying for your case.
First: Setup your grid as you would normally, item source and columns, standard data binding. This will take care of any columns you need from the database or other source.
Second: In your project add your static class
Third: Add your new resource to app resources
Finally: Set the binding in your
TextBlock, if you’ve built your project, you should be able to see the property in the binding editor window.