开发者

WPF DataGrid Text wrapping in headers and elsewhere

开发者 https://www.devze.com 2023-03-08 14:31 出处:网络
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

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:primitiv开发者_运维问答es="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?


Please see this first Text wrapping in WPF DataGrid column header


The reference to app.xaml is not required as can be seen here:

<DataGrid Name="WBdataGrid" AutoGenerateColumns="False" ColumnHeaderHeight="50" >
  <DataGrid.ColumnHeaderStyle>
    <Style TargetType="DataGridColumnHeader">
      <Setter Property="ContentTemplate">
        <Setter.Value>
          <DataTemplate>
            <TextBlock TextWrapping="Wrap" Text="{Binding}"></TextBlock>
          </DataTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </DataGrid.ColumnHeaderStyle>
<DataGrid.Columns>
0

精彩评论

暂无评论...
验证码 换一张
取 消