Пытаюсь сделать перенос текста на новую строку в зависимости от ширины колонки в datagrid. Получилось, но в ячейках отображается
System.Data.DataRowView. Что я делаю не так?
Данные в таблицу загружаю из БД следующим образом:
dataGrid1.ItemsSource = r2.ResultData.DefaultView;
<Window.Resources>
<DataTemplate x:Key="templ">
<TextBlock Text="{Binding}" TextWrapping="Wrap" Foreground="Black" />
</DataTemplate>
</Window.Resources>
<Grid>
<DataGrid Name="dataGrid1"
DockPanel.Dock="Left"
SelectionUnit="FullRow"
SelectionMode="Single"
HeadersVisibility="Column"
IsReadOnly="True"
AutoGeneratingColumn="dataGrid1_AutoGeneratingColumn" >
</DataGrid>
</Grid>
private void dataGrid1_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
if (e.Column.Header.ToString() == "NAME_DOC")
{
e.Column.Header = "Наименование";
// ...
Style style = new Style(typeof(DataGridCell));
style.Setters.Add(new Setter(DataGridCell.ContentTemplateProperty, Resources["templ"]));
e.Column.CellStyle = style;
}
}