使用 DataGrid 列转换器

发布于 2024-09-27 13:27:20 字数 214 浏览 10 评论 0原文

我使用 MVVM 模式创建 Windows 数据库基础设施。我有为我的 DataGrid 返回数据的方法。 问题是,我希望 DataGrid 中的某些列使用转换器 (IValueConverter),但我将 DataGrid 直接绑定到数据。我无法在 xaml 中强类型列规范,因为列数可能不同。另外,我无法在 ViewModel 中获取 UI 元素(DataGrid)进行更改。

I create my windows databainding infrastructure with MVVM pattern. I have method which return data for my DataGrid. Problem that I want some columns in DataGrid use Converter (IValueConverter) but I bind my DataGrid to the data directly. I can't strongly type columns specification in xaml because number of columns can be different. Also I can't get UI element (DataGrid) in ViewModel for change.

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

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

发布评论

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

评论(1

他夏了夏天 2024-10-04 13:27:20

您的 ViewModel 可以公开列集合(可以指定列标题、数据类型、使用转换器的必要信息的结构)将其绑定到视图的 DP,并且您的视图需要在解析该集合并准备数据模板后将列添加到数据网格对于数据网格列的单元格模板和单元格编辑模板,指定绑定源、转换器。

Your ViewModel can expose the column collection (structure which can specify column header, type of data, necessary information to use converter) bind that to a DP of your view and your view needs to add the columns to the datagrid after parsing that and preparing datatemplate for datagrid column's cell template and cell edittemplate which specifies the binding source, converter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文