Answer the question
In order to leave comments, you need to log in
How to wrap text in datagrid cells?
I'm trying to make text wrap to a new line depending on the width of the column in the datagrid. It worked, but the cells show System.Data.DataRowView . What am I doing wrong?
I load the data into the table from the database as follows: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;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question