B_old B_old - 1 month ago 10
C# Question

WPF DataGrid Text wrapping in headers and elsewhere

I want to enable text wrapping in the WPF DataGrid column headers and the content of the rows.
Searching for solutions, I often stumble over something like this. The problem is, that it is not working for me.

First of all I have problems with this line:

xmlns:primitives="clr-namespace:Microsoft.Windows.Controls.Primitives;assembly=WPFToolkit"


I get errors about the assembly not being found.
More problems with the rest of the XAML-code.

<Style TargetType="{x:Type primitives:DataGridColumnHeader}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock TextWrapping="Wrap" Text="{Binding}"></TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>


I place this inside the DataGrid tag, otherwise it won't compile. I also omit the "primitives"-namespace as I did not actually include it (see above). Now it compiles. However the application throws some exception in the constructor of the window. Any idea how I can get this thing to actually work?

Answer
Comments