WPF - ItemsSource 相当于 FlowDocument 中的表?

发布于 2024-09-18 20:23:51 字数 586 浏览 1 评论 0 原文

我正在尝试在 FlowDocumentPageViewer 内的 FlowDocument 内创建一个 Table,如 本教程。我以前从未在 WPF 中创建过表,并且希望有一个可以绑定的 ItemsSource 属性,就像使用 ListBox 一样。我想为每一行自定义模板,并且希望每一行的源都是我传递到整个表的集合中的一个项目。因此,我将有一个将传递到表的 List 实例,并且每行将显示一个 MyClass。我怎样才能做到这一点?我不想在 FlowDocument 中使用 Table 吗?我想使用某种表格格式的原因是这样我可以拥有适用于所有行的单行列名称。

I'm trying to create a Table inside a FlowDocument inside a FlowDocumentPageViewer, as seen in this tutorial. I've never created a table in WPF before, and I was expecting there to be an ItemsSourceproperty to which I could bind, like with a ListBox. I want to customize the template for each row, and I want each row's source to be an item in a collection that I pass to the entire table. So I'll have a List<MyClass> instance that would be passed to the table, and each row would show a single MyClass. How can I do that? Do I not want to use a Table within a FlowDocument? The reason I wanted to use some kind of tabular format is so that I can have a single row of column names that applies to all the rows.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懒的傷心 2024-09-25 20:23:51

我想我想要的是使用 ListView,感谢 本教程

<ListView Grid.Row="0" ItemsSource="{Binding Path=MyList}" MinWidth="400"
    MinHeight="200">
    <ListView.View>
        <GridView>
            <GridView.Columns>
                <GridViewColumn
                    DisplayMemberBinding="{Binding Path=MyFirstField}"
                    Header="First Field"/>
                <GridViewColumn
                    DisplayMemberBinding="{Binding Path=MySecondField}"
                    Header="Second Field"/>
            </GridView.Columns>
        </GridView>
    </ListView.View>
</ListView>

I think what I wanted was to use ListView, thanks to this tutorial:

<ListView Grid.Row="0" ItemsSource="{Binding Path=MyList}" MinWidth="400"
    MinHeight="200">
    <ListView.View>
        <GridView>
            <GridView.Columns>
                <GridViewColumn
                    DisplayMemberBinding="{Binding Path=MyFirstField}"
                    Header="First Field"/>
                <GridViewColumn
                    DisplayMemberBinding="{Binding Path=MySecondField}"
                    Header="Second Field"/>
            </GridView.Columns>
        </GridView>
    </ListView.View>
</ListView>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文