ListView显示System.Data.DataRowView而不是DataTable

时间:2014-03-21 08:15:02

标签: c# .net wpf listview datatable

我的问题是ListView的每一行都显示" System.Data.DataRowView"在我用样式更改ListView模板后。

我在这里定义了DataTable:

DataTable data = new DataTable();
lsvOutput.ItemsSource = data.DefaultView;

这是列的XAML:

            <ListView.View>
                <GridView>
                    <GridViewColumn Header="column1" DisplayMemberBinding="{Binding column1}"/>
                    <GridViewColumn Header="column2" DisplayMemberBinding="{Binding column2}"/>
                    <GridViewColumn Header="column3" DisplayMemberBinding="{Binding column3}"/>
                </GridView>
            </ListView.View>

这是它打破的部分我假设:

                    <ContentPresenter
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>

1 个答案:

答案 0 :(得分:0)

我明白了。我取代了这个:

<ContentPresenter
                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>

有了这个:

<GridViewRowPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />

来源:http://msdn.microsoft.com/en-us/library/ms788747%28v=vs.110%29.aspx