GridViewColumn.CellTemplate中的TextBlock文本换行不起作用 [英] TextBlock text wrapping in GridViewColumn.CellTemplate not working

查看:150
本文介绍了GridViewColumn.CellTemplate中的TextBlock文本换行不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此示例中,我无法使TextWrapping正常工作。有人能看到我在这里犯错吗?

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>


推荐答案

您同时设置了 DisplayMemberBinding CellTemplate 。使用 CellTemplate 时,删除 DisplayMemberBinding 。还要删除 TextBlock Width ,它将起作用

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>

这篇关于GridViewColumn.CellTemplate中的TextBlock文本换行不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆