This question is locked. New answers and comments are not allowed.
Hi there,
I have read the threads in this forum about binding data to the header of a grid column, and the suggestion seems to be declaring your viewmodel class in the resources section of your xaml and referencing it as a StaticResource. I tried this and got errors, I think because I do no use a default constructor. The error i get is 'No matching constructor found on type 'myViewModel'. My viewModel's constructor takes in some interfaces as parameters. If I put in a default constructor in, I dont get the error, but my column headers are empty, I assume because it has created a new viewModel with the default constructor and not using my DataContext which has the correct column heading.
When I tried to solve same thing with the normal Silverlight DataGrid, I extracted out the style of the DataGridColumnHeader in my resources section, and in the ControlTemplate, I put this code in and it worked:
<ContentPresenter>
<TextBlock Text="{Binding ErrorHeading}"/>
</ContentPresenter>
So I tried to do the same thing with the Telerik control, when I edited the style of the GridViewHeaderCell, It had this line which was slightly different to the one which worked above:
<ContentControl x:Name="ContentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Grid.Column="0" ForeGround="{TemplateBinding Foreground}" Style="{StaticResource StretchedContentControl}" />
I tried replacing the content with my binding like this:
<ContentControl .... etc >
<ContentControl.Content>
<TextBlock Text="{Binding ErrorHeading}" />
</ContentControl.Content>
</ContentControl>
But the binding still does not work. If I change the binding to plain text, it works. Any help would be much appreciated.
Thanks,
Stephen
I have read the threads in this forum about binding data to the header of a grid column, and the suggestion seems to be declaring your viewmodel class in the resources section of your xaml and referencing it as a StaticResource. I tried this and got errors, I think because I do no use a default constructor. The error i get is 'No matching constructor found on type 'myViewModel'. My viewModel's constructor takes in some interfaces as parameters. If I put in a default constructor in, I dont get the error, but my column headers are empty, I assume because it has created a new viewModel with the default constructor and not using my DataContext which has the correct column heading.
When I tried to solve same thing with the normal Silverlight DataGrid, I extracted out the style of the DataGridColumnHeader in my resources section, and in the ControlTemplate, I put this code in and it worked:
<ContentPresenter>
<TextBlock Text="{Binding ErrorHeading}"/>
</ContentPresenter>
So I tried to do the same thing with the Telerik control, when I edited the style of the GridViewHeaderCell, It had this line which was slightly different to the one which worked above:
<ContentControl x:Name="ContentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Grid.Column="0" ForeGround="{TemplateBinding Foreground}" Style="{StaticResource StretchedContentControl}" />
I tried replacing the content with my binding like this:
<ContentControl .... etc >
<ContentControl.Content>
<TextBlock Text="{Binding ErrorHeading}" />
</ContentControl.Content>
</ContentControl>
But the binding still does not work. If I change the binding to plain text, it works. Any help would be much appreciated.
Thanks,
Stephen