Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextBlock text wrapping in GridViewColumn.CellTemplate not working

I am having problems getting the TextWrapping to work in this example. Can anyone see what I am duing wrong here?

    <ListView Name="listViewReportedException" ItemsSource="{Binding ExceptionDetails}">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="Time" DisplayMemberBinding="{Binding Thrown}" Width="150" />
                <GridViewColumn Header="Description" DisplayMemberBinding="{Binding Description}" Width="385">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock TextWrapping="Wrap" Text="{Binding}" Width="385"/>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Header="Recover action" DisplayMemberBinding="{Binding Action}" Width="90"/>
            </GridView>
        </ListView.View>
    </ListView>
like image 712
mola Avatar asked Jun 19 '12 12:06

mola


1 Answers

You are setting both DisplayMemberBinding and CellTemplate. Remove DisplayMemberBinding when you use CellTemplate. Also remove the Width for the TextBlock and it'll work

<ListView ...>
    <ListView.View>
        <GridView>
            <!-- ... -->
            <GridViewColumn Header="Description" Width="385">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock TextWrapping="Wrap" Text="{Binding Description}" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <!-- ... -->
        </GridView>
    </ListView.View>
</ListView>
like image 177
Fredrik Hedblad Avatar answered Oct 07 '22 00:10

Fredrik Hedblad