简体   繁体   English

看起来像Excel的WPF窗口

[英]WPF window that looks like excel

I am new to WPF and c#, and I am trying trying to create an excel like table with a fixed number of columns and a varying number of rows according to the user's needs.People advise to use a datagrid, but I am very confused, some say that it is used mostly to display data source content (which is data contained in database if I understood). 我是WPF和c#的新手,我试图根据用户的需要创建具有固定列数和不同行数的excel表。人们建议使用datagrid,但我很困惑,有人说它主要用于显示数据源内容(据我了解,它是数据库中包含的数据)。 I read also about listviews, binding things to itemsource...etc. 我还阅读了有关列表视图,将内容绑定到itemsource等的信息。 This is really a lot of information to work with! 这确实是很多有用的信息! What I simply need is a way to create a table with fixed columns, and adding rows automatically when the user clicks on a button, that's it! 我只需要一种创建带有固定列的表,并在用户单击按钮时自动添加行的方法! No binding, or anything of this sort.But how to achieve that? 没有绑定或任何此类绑定,但是如何实现呢? Also, if you have good websites tutorials for working with datagrids, I would be very grateful (most of those that I found are too much complex, or don't explain well). 另外,如果您有使用数据网格的良好网站教程,我将不胜感激(我发现其中的大多数过于复杂,或者无法很好地解释)。

Thanks a lot! 非常感谢!

You can create datatemplates that will style your data to look however you like - in this case an Excel row. 您可以创建数据模板,该模板将对数据进行样式设置以使其具有您喜欢的样式-在这种情况下为Excel行。 Then you can display this data as the ItemsSource in an items control. 然后,您可以在项目控件中将此数据显示为ItemsSource。 Since you want the number of rows to vary based on some criteria, your data should be in an ObservableCollection. 由于您希望行数根据某些条件而变化,因此您的数据应位于ObservableCollection中。 I'm not sure how you'd set-up the header, but I think you could style-up some containers and bind their width properties to the datatemplate controls. 我不确定如何设置标题,但我认为您可以设置一些容器的样式并将其width属性绑定到datatemplate控件。

如果您希望进行更多的单元级别自定义,则可以尝试使用Grid http://www.syncfusion.com/products/user-interface-edition/wpf/grid/grid-control

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM