0
votes

I have an xaml like:

<GroupBox Header="groupBox1" Height="174" HorizontalAlignment="Left" Margin="36,38,0,0" Name="groupBox1" VerticalAlignment="Top" Width="285">
        <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
            <Grid x:Name="caseListGrid">
            </Grid>
        </ScrollViewer>
</GroupBox>

and in the .cs file i have a function:

private void LoadDataGrid()
{
    caseElementList = new List<CaseElement>();
    caseElementList.Clear();

    //add 1st element
    caseElementList.Add(new CaseElement
    {
        CaseName = "First Name",
        Description = "Recently I came across the need to customize the look of the standard message box in the application. To do this I’ve decided to create a new class named WPFMessageBox"
    });

    //add second
    caseElementList.Add(new CaseElement
    {
        CaseName = "Second Name",
        Description = "Recently I came across the need to customize the look of the standard message box in the application. To do this I’ve decided to create a new class named WPFMessageBox"
    });

    caseElementList.Add(new CaseElement
    {
        CaseName = "Third Name",
        Description = "Recently I came across the need to customize the look of the standard message box in the application. To do this I’ve decided to create a new class named WPFMessageBox"
    });


    DataGrid dGrid = new DataGrid();                        
    dGrid.AutoGenerateColumns = true;            
    dGrid.ItemsSource = caseElementList;
    this.caseListGrid.Children.Add(dGrid);
}

here in the function i have created a List of custom case objects. Then i have assigned the list to the datagrid (after creating the datagrid).

But as because i have not added styles in the datagrid.. and the texts are very big. So, it is expanding in a scrollview.

But i want to display them using text wrapping. So, can anyone give me any solution??

I have found that using textblock it can be solved. But i can't figured out how i can add textblocks in that datagrid as because i am creating this dynamically..!!

1

1 Answers

0
votes

Solution 1: Do not AutoGenerateColumns and specify the columns yourself.

Solution 2: Subscribe to the AutoGeneratingColumn event and change the column to something that wraps (e.g. using the ElementStyle property of the column).